返回结果:
list<string> 类型,数组中保存“文件中代码不正确,正确代码为xxxxx"这句话是个什么意思?能不能举个例子帮说明一下?另外:我想方法应该这样定义,返回值怎么破,能不能举个例子说明下?
public bool CheckYSDM( out List<string> result)
{}谢谢了!
list<string> 类型,数组中保存“文件中代码不正确,正确代码为xxxxx"这句话是个什么意思?能不能举个例子帮说明一下?另外:我想方法应该这样定义,返回值怎么破,能不能举个例子说明下?
public bool CheckYSDM( out List<string> result)
{}谢谢了!
{
List<string> result = null;
CheckYSDM(out result); Array.ForEach(result.ToArray(), c => Console.WriteLine(c)); Console.ReadLine();
}public static bool CheckYSDM(out List<string> result)
{
result = new List<string>();
result.Add("str1");
result.Add("str2"); return true;
}
第二个
public bool CheckYSDM( List<string> result)
如果你对result进行添加,不用加out
第一个就是最后结果返回值必须是list<string>类型
list<string>中保存“文件中代码不正确,正确代码为xxxxx"
我的数据字典Dictionary<string, string>中存的"1000110001, Point"做比对,如果前边的编码不一致,返回一个List<string>类型,存储错误信息“文件中代码不正确,正确代码为xxxxx"当然读出来的字符串是一系列类似的,数据字典中的也是一系列的。
例如:
000110000,Point
1000110408,Line
1000600100,Polygon我想问的是List<string>作为一个这样一个返回类型该怎么用? 就像我定义的那个方法那样
{
List<string> l = new List<string>();
l.Add("文件中代码不正确,正确代码为xxxxx");
return l;
}
000110000,Point
哪个是Key,哪个是Value
按你的描述,应该是
Value,Key
那么代码应该类似:List<string> foo(List<string> input, Dictionary<string, string> dic)
{
List<string> result = new List<string>();
input.ForEach(s =>
{
var sr = s.Split(',');
if (dic.ContainsKey(sr[1]) && dic[sr[1]] != sr[0])
result.Add(string.Format("文件中代码不正确,正确代码为{0}", dic[sr[0]]));
}
return result;
}
纯手写也许有错误