Hello!
Please tell me how to rewrite the function GetValues() using LINQ.
And if you give a sensible link to learning LINQ (except for MSDN), I will be grateful.
Here is the code:
enum MyEnum { FIRST, SECOND }; class MyClass { List<MyObject> MyList = new List<MyObject>(); //constructor internal MyClass() { MyList.Add(new MyObject(MyEnum.FIRST, 1)); MyList.Add(new MyObject(MyEnum.FIRST, 2)); MyList.Add(new MyObject(MyEnum.FIRST, 3)); MyList.Add(new MyObject(MyEnum.SECOND, 1)); List<int> collectedValues = GetValues(MyList, MyEnum.SECOND); } List<int> GetValues(List<MyObject> MyList, MyEnum ExceptionEnum) { List<int> returnList = new List<int>(); for(int i = 0; i < MyList.Count; i++) { if(MyList[i].MyName == ExceptionEnum) continue; returnList.Add(MyList[i].Value); } return returnList; } } class MyObject { internal MyEnum MyName; internal int Value; public MyObject(MyEnum MyName, int Value) { this.MyName = MyName; this.Value = Value; } }