问这个问题我觉得很愚蠢,但我有两种方法,除了命名约定外,它们的代码几乎相同......我想缩短它以减少冗余代码的使用。我该如何缩短这个?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Text.RegularExpressions;
namespace empTRUST
{
class DBDictionary : DBBase
{
public DBDictionary()
: base("Dictionary", "Word")
{
}
public List<DataRow> AngerPercent(string status)
{
List<DataRow> dataList = new List<DataRow>();
var wordPattern = new Regex(@"\w+");
DataRow[] rows = fbTab.Select("Genre = 'Angry'");
foreach (Match match in wordPattern.Matches(status))
foreach (var item in rows)
if (item["Word"].ToString().ToLower() == match.ToString().ToLower())
{
dataList.Add(item);
}
return dataList;
}
public List<DataRow> CaringPercent(string status)
{
List<DataRow> dataList = new List<DataRow>();
var wordPattern = new Regex(@"\w+");
DataRow[] rows = fbTab.Select("Genre = 'Caring'");
foreach (Match match in wordPattern.Matches(status))
foreach (var item in rows)
if (item["Word"].ToString().ToLower() == match.ToString().ToLower())
{
dataList.Add(item);
}
return dataList;
}
}
}