Skip to content

Commit 979318f

Browse files
semantic and syntactic improvements
Geringe syntaktische Anpassung und semantische Verbesserungsvorschläge
2 parents 1c38550 + 78fe396 commit 979318f

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

26_LINQ.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -835,12 +835,13 @@ Der Vorteil anonymer Typen liegt in ihrer Flexibilität. Die eigentlichen Daten
835835

836836
```csharp
837837
public interface IEnumerable<out T> : System.Collections.IEnumerable{
838-
public IEnumerator<T> = GetEnumerator();
838+
public IEnumerator<T> GetEnumerator();
839839
}
840840

841841
public interface IEnumerator<out T> : IDisposable,
842842
System.Collections.IEnumerator{
843-
public object Current { get; }
843+
public T Current { get; }
844+
public void Dispose();
844845
public bool MoveNext ();
845846
public void Reset ();
846847
}
@@ -1005,21 +1006,21 @@ class Student{
10051006
public string Name;
10061007
public int Id;
10071008
public string Subject{get; set;}
1008-
public Student(){}
1009+
public Student(string name){ this.Name = name; }
10091010
}
10101011

10111012
// Collection Initialization
10121013
List<Student> students = new List<Student>{
1013-
new Student("Max Müller"){Subject = "Technische Informatik", id = 1},
1014-
new Student("Maria Maier"){Subject = "Softwareentwicklung", id = 2},
1015-
new Student("Martin Morawschek"){Subject = "Höhere Mathematik I", id = 3}
1016-
}
1014+
new Student("Max Müller"){Subject = "Technische Informatik", Id = 1},
1015+
new Student("Maria Maier"){Subject = "Softwareentwicklung", Id = 2},
1016+
new Student("Martin Morawschek"){Subject = "Höhere Mathematik I", Id = 3}
1017+
};
10171018

10181019
// Implizite Typdefinition
10191020
var result = from s in students // Spezifikation der Datenquelle
1020-
where s.Subject == "Softwarentwicklung"
1021+
where s.Subject == "Softwareentwicklung"
10211022
orderby s.Name
1022-
select new (s.Name, s.Id) // Projektion der Ausgabe
1023+
select new { s.Name, s.Id }; // Projektion der Ausgabe
10231024
10241025
// explizite Typdefinition
10251026
IEnumerable<Student> result = from s in students
@@ -1405,7 +1406,7 @@ class Program {
14051406
new Student("Karl Tischer"){Subject = "Softwareentwicklung", id = 5},
14061407
};
14071408
var query = from s in students
1408-
select new {Surname = s.Name.Split(' ')[0]};
1409+
select new {Surname = s.Name.Split(' ')[1]};
14091410
Console.WriteLine(query.GetType());
14101411
foreach (var student in query){
14111412
Console.WriteLine(student.Surname);

0 commit comments

Comments
 (0)