static void Main(string[] args) { //5,6,7,8,9 VectorList<User> Users = new VectorList<User>(5); Users.elements[0] = new User { Id = 1, Name = "John", Phone = "1234567", Age = 20 }; Users.elements[1] = new User { Id = 2, Name = "Jane", Phone = "4365745674", Age = 40 }; Users.elements[2] = new User { Id = 3, Name = "Max", Phone = "34563546", Age = 60 }; Users.elements[3] = new User { Id = 4, Name = "Eva", Phone = "96798", Age = 80 }; Users.elements[4] = new User { Id = 5, Name = "Mickel", Phone = "3245", Age = 100 }; var temp = Users.Select(x=>x.Age>30 && x.Age<100).Select(x=> { string newname = x.Name = " " + x.Age; return new { Name = newname, Age = x.Age }; }).Select(x => x.Name); double maxage = Users.max(x => x.Age) }
public VectorList <Tunknown> Select <Tunknown>(Func <T, Tunknown> f) { VectorList <Tunknown> tu = new VectorList <Tunknown>(this.Length); for (int i = 0; i < this.Length; i++) { tu[i] = f(this[i]); } return(tu); }
public VectorList<TResult> Select(Func<T, TResult> f) { VectorList<TResult> outlist = new VectorList<TResult>(elements.Length); for(int i=0;i<elements.Length;i++) { outlist.elements[i] = f(elements[i]); } return outlist; }
public VectorList <T> Where(Func <T, bool> f) { int[] selected = new int[Length]; int count = 0; for (int i = 0; i < Length; i++) { if (f(this[i])) { selected[count] = i; count++; } } VectorList <T> res = new VectorList <T>(count); for (int i = 0; i < count; i++) { res[i] = this[selected[i]]; } return(res); }
public VectorList<T> Where(Func<T,bool> filter) { int[] appr = new int[elements.Length]; int counter = 0; for(int i=0;i<elements.Length; i++) { if(filter(elements[i])) { appr[counter] = i; counter++; } } VectorList<T> t = new VectorList<T>(counter); for (int i = 0; i < counter; i++) { res.elements[i] = elements[appr[i]]; } return null; }
static void Main(string[] args) { VectorList <User> Users = new VectorList <User>(5); Users[0] = new User { Id = 1, Name = "John", Phone = "1234567", Age = 20 }; Users[1] = new User { Id = 2, Name = "Jane", Phone = "4365745674", Age = 40 }; Users[2] = new User { Id = 3, Name = "Max", Phone = "34563546", Age = 60 }; Users[3] = new User { Id = 4, Name = "Eva", Phone = "96798", Age = 80 }; Users[4] = new User { Id = 5, Name = "Mickel", Phone = "3245", Age = 100 }; var tu1 = Users.Select(x => new { User = x.Name, Phone = long.Parse(x.Phone) }); var olds = Users.Where(x => x.Age > 40).Where(x => x.Age < 80).Select(x => new { User = x.Name, Phone = long.Parse(x.Phone) }); }