I want to select specific members whose phones start with "02". I have class Student with this constructor
public Student(string firstName, string lastName, int fn, int tel, string email, List<int> allMarks, int groupNumber)
Make a List<Student> students
.
And that I want to do is to select this members that their telephone start with '02' (for my example)
I try this:
1st
var tel = students.Where(x => x.Tel.ToString().StartsWith("02")).ToArray();
Print(tel);
2nd
var testTel = students
.Select(x => x.Tel.ToString().Substring(0, 2) == "02")
.Select(x => x);
Print(testTel);
3rd
var someTel =
from t in students
where t.Tel.ToString().Substring(0, 2).Equals("02")
select t.Tel;
And some more... but on the end I make (convert /int Tel to string Tel/) and work.
I want to ask is there a way to select this member when int Tel
part of list:
List<Student> students = new List<Student>()
{
new Student("Nataly", "Adams", 8222, 029669, "hot@mail.com",
new List<int>{2, 3, 3, 5, 6}, 2),
new Student("Ben", "Dueyn", 8215, 0886996321, "hot@mail.com",
new List<int>{4, 5, 4, 5, 5}, 2),
};