Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Newbie in LINQ - Just a quick question

Newbie in LINQ - Just a quick question

Scheduled Pinned Locked Moved LINQ
questioncsharpdatabaselinqregex
2 Posts 2 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Programm3r
    wrote on last edited by
    #1

    Hi all, I am tryin go run the query based on two lists, where the one list matches the other list. In the example below,I'm trying to match the teacher with the student with regards to their subjects. I am struggling ... Can anyone please help ?? class Student { public string First { get; set; } public string Last { get; set; } public string Subject { get; set; } public string Street { get; set; } public string City { get; set; } public List<int> Scores; } class Teacher { public string First { get; set; } public string Last { get; set; } public string Subject { get; set; } public string City { get; set; } } ... List<Student> students = new List<Student>() { new Student {First="Svetlana", Last="Omelchenko", Subject="English", Scores= new List<int> {97, 92, 81, 60}}, new Student {First="Claire", Last="O’Donnell", Subject="Biology", Scores= new List<int> {75, 84, 91, 39}}, new Student {First="Sven", Last="Mortensen", Subject="Afrikaans", Scores= new List<int> {88, 94, 65, 91}}, new Student {First="Cesar", Last="Garcia", Subject="Science", Scores= new List<int> {97, 89, 85, 82}}, new Student {First="Debra", Last="Garcia", Subject="Earch Sience", Scores= new List<int> {35, 72, 91, 70}}, new Student {First="Fadi", Last="Fakhouri", Subject="English", Scores= new List<int> {99, 86, 90, 94}}, new Student {First="Hanying", Last="Feng", Subject="German", Scores= new List<int> {93, 92, 80, 87}}, new Student {First="Hugo", Last="Garcia", Subject="Programming", Scores= new List<int> {92, 90, 83, 78}}, new Student {First="Lance", Last="Tucker", Subject="Social Studies", Scores= new List<int> {68, 79, 88, 92}}, new Student {First="Terry", Last="Adams", Subject="Science", Scores= new List<int> {99, 82, 81, 79}}, new Student {First="Eugene", Last="Zabokritski", Subject="Afrikaans", Scores= new List<int> {96, 85, 91, 60}}, new Student {First="Michael", Last="Tucker", Subject="Zulu", Scores= new List<int> {94, 92, 91, 91} }, }; // Create the second data source. List<Teacher> teachers = new List<Teacher>() { new Teacher {First="Ann", Last="Beebe", Subject="Af

    E 1 Reply Last reply
    0
    • P Programm3r

      Hi all, I am tryin go run the query based on two lists, where the one list matches the other list. In the example below,I'm trying to match the teacher with the student with regards to their subjects. I am struggling ... Can anyone please help ?? class Student { public string First { get; set; } public string Last { get; set; } public string Subject { get; set; } public string Street { get; set; } public string City { get; set; } public List<int> Scores; } class Teacher { public string First { get; set; } public string Last { get; set; } public string Subject { get; set; } public string City { get; set; } } ... List<Student> students = new List<Student>() { new Student {First="Svetlana", Last="Omelchenko", Subject="English", Scores= new List<int> {97, 92, 81, 60}}, new Student {First="Claire", Last="O’Donnell", Subject="Biology", Scores= new List<int> {75, 84, 91, 39}}, new Student {First="Sven", Last="Mortensen", Subject="Afrikaans", Scores= new List<int> {88, 94, 65, 91}}, new Student {First="Cesar", Last="Garcia", Subject="Science", Scores= new List<int> {97, 89, 85, 82}}, new Student {First="Debra", Last="Garcia", Subject="Earch Sience", Scores= new List<int> {35, 72, 91, 70}}, new Student {First="Fadi", Last="Fakhouri", Subject="English", Scores= new List<int> {99, 86, 90, 94}}, new Student {First="Hanying", Last="Feng", Subject="German", Scores= new List<int> {93, 92, 80, 87}}, new Student {First="Hugo", Last="Garcia", Subject="Programming", Scores= new List<int> {92, 90, 83, 78}}, new Student {First="Lance", Last="Tucker", Subject="Social Studies", Scores= new List<int> {68, 79, 88, 92}}, new Student {First="Terry", Last="Adams", Subject="Science", Scores= new List<int> {99, 82, 81, 79}}, new Student {First="Eugene", Last="Zabokritski", Subject="Afrikaans", Scores= new List<int> {96, 85, 91, 60}}, new Student {First="Michael", Last="Tucker", Subject="Zulu", Scores= new List<int> {94, 92, 91, 91} }, }; // Create the second data source. List<Teacher> teachers = new List<Teacher>() { new Teacher {First="Ann", Last="Beebe", Subject="Af

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      It would have been helpful if you explained exactly what you wanted but is this the kind of thing you're after?

      var results = from s in students
      where teachers.FirstOrDefault(t => (t.Subject == s.Subject)) != null
      select s.Last + " " + s.First + " MARK: " + s.Scores[0];


      I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups