我有这样的结构
List<int[]> propIDs = new List<int[]>();
Run Code Online (Sandbox Code Playgroud)
我可以使用LINQ从propID获取所有唯一值.例如,我有(1,2)(4,5)(1,5)(1,2)(1,5)的列表,我必须得到(1,2) )(4,5)(1,5)
所以,说我有以下内容:
public class Element
{
public int ID;
public int Type;
public Properties prorerty;
...
}
和
public class Properties
{
public int Id;
public string Property;
...
}
Run Code Online (Sandbox Code Playgroud)
我有一个列表:
List Elements = new List();Run Code Online (Sandbox Code Playgroud)
在Element类的prorerty列中获取所有不同值的列表最简洁的方法是什么?我的意思是,我可以遍历列表并将所有不重复的值添加到另一个字符串列表中,但这看起来很脏且效率低下.我有一种感觉,有一些神奇的Linq结构可以在一条线上做到这一点,但我无法想出任何东西.
我有
SortedList<string, object> testIds = new SortedList<string, object>();
Run Code Online (Sandbox Code Playgroud)
我把它按降序排列.我用于排序下一个结构:
testIds.ToList().Sort(delegate(KeyValuePair<string, object>x, KeyValuePair<string, object>y)
{
return x.Key.CompareTo(y.Key)*-1;
});
Run Code Online (Sandbox Code Playgroud)
但它没有帮助我.你能给我一些建议如何解决这个问题?
我有
int[] array1 = { 1, 2, 3 };
int[] array2 = { 2, 3, 4 };
Run Code Online (Sandbox Code Playgroud)
用var intersect = array1.Intersect(array2);我得到了
2
3
Run Code Online (Sandbox Code Playgroud)
但我需要得到
1
4
Run Code Online (Sandbox Code Playgroud)
您能否告诉我如何使用Linq做到这一点?
我有这样的结构:
FileStream fs = new FileStream(fileName, FileMode.Open);
StreamReader sr = new StreamReader(fs);
while (!sr.EndOfStream)
{
string line=sr.ReadLine();
fullTextLines.Add(line);
}
Run Code Online (Sandbox Code Playgroud)
和一些文字:
string txt = "begin
middle
i am a string
i am a string end"
Run Code Online (Sandbox Code Playgroud)
我想获得包含"我是"的最后一行索引.例如:我必须得到3但是当我使用时Console.WriteLine(fullTextLines.LastIndexOf("GRID"));我得到-1.