Step 1) Create a sample Class let say MyClass:
public class MyClass{
public int Age { get; set; }
public string TelephoneNumber { get; set; }
public string Name { get; set; }
}
Step 2) Create List of class and add some dummy values in list
objMyClass = new MyClass();
objMyClass.Age = 39;
objMyClass.Name = "mahesh";
objMyClass.TelephoneNumber = "9876561364";
objListOfMyClass.Add(objMyClass);
objMyClass = new MyClass();";"";
objMyClass = new MyClass();
objMyClass = "nabhay";
objMyClass.Age = 22;
objMyClass.Name = "rakshit";
objMyClass.TelephoneNumber = ""
objListOfMyClass.Add(objMyClass);
objMyClass =
objMyClass.Age = 18;
objMyClass.Name =
objMyClass.TelephoneNumber =
objListOfMyClass.Add(objMyClass);
Step 3)
Create new class in which we will create property to set the number of arguments and value, In real project we will only using the set attribute of property.
public class MyListMatcher{
public int Age { get; set; }
public string TelephoneNumber { get; set; }
public string Name { get; set; }
public bool Predicate(MyClass item)return ((item.Age == Age) && (item.TelephoneNumber == TelephoneNumber) && (item.Name == Name));}
Step 4) Now we have List and Predicated implemented logic so we have to just use it
objMyListMathcer.Name = "rakshit";
objMyListMathcer.Age = 18;
objMyListMathcer.TelephoneNumber = "987654321";
MyListMatcher objMyListMathcer = new MyListMatcher();
List<MyClass> objSelecteRes = objListOfMyClass.FindAll(objMyListMathcer.Predicate).ToList();
Thanks
Mahesh K. Sharms
public class MyClass{
public int Age { get; set; }
public string TelephoneNumber { get; set; }
public string Name { get; set; }
}
Step 2) Create List of class and add some dummy values in list
objMyClass = new MyClass();
objMyClass.Age = 39;
objMyClass.Name = "mahesh";
objMyClass.TelephoneNumber = "9876561364";
objListOfMyClass.Add(objMyClass);
objMyClass = new MyClass();";"";
objMyClass = new MyClass();
objMyClass = "nabhay";
objMyClass.Age = 22;
objMyClass.Name = "rakshit";
objMyClass.TelephoneNumber = ""
objListOfMyClass.Add(objMyClass);
objMyClass =
objMyClass.Age = 18;
objMyClass.Name =
objMyClass.TelephoneNumber =
objListOfMyClass.Add(objMyClass);
Step 3)
Create new class in which we will create property to set the number of arguments and value, In real project we will only using the set attribute of property.
public class MyListMatcher{
public int Age { get; set; }
public string TelephoneNumber { get; set; }
public string Name { get; set; }
public bool Predicate(MyClass item)return ((item.Age == Age) && (item.TelephoneNumber == TelephoneNumber) && (item.Name == Name));}
Step 4) Now we have List and Predicated implemented logic so we have to just use it
objMyListMathcer.Name = "rakshit";
objMyListMathcer.Age = 18;
objMyListMathcer.TelephoneNumber = "987654321";
MyListMatcher objMyListMathcer = new MyListMatcher();
List<MyClass> objSelecteRes = objListOfMyClass.FindAll(objMyListMathcer.Predicate).ToList();
Thanks
Mahesh K. Sharms
No comments:
Post a Comment