-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7773be
commit f5e8e56
Showing
4 changed files
with
30 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
public record Person(string name); | ||
|
||
var persons = new List<Person>() { new("p1"), new("p2") }; | ||
|
||
// Using a for loop | ||
for (int i = 0; i < persons.Count; i++) | ||
namespace NewLINQMethodsCsharp13 | ||
{ | ||
var person = persons[i]; | ||
Console.WriteLine($"Index: {i}, Person:{person}"); | ||
} | ||
public record Person(string name); | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var persons = new List<Person>() { new("p1"), new("p2") }; | ||
|
||
// Using the new .NET 9 Index method. | ||
foreach ((int index, Person person) in persons.Index()) | ||
{ | ||
Console.WriteLine($"Index: {index}, Person:{person}"); | ||
// Using a for loop | ||
for (int i = 0; i < persons.Count; i++) | ||
{ | ||
var person = persons[i]; | ||
Console.WriteLine($"Index: {i}, Person:{person}"); | ||
} | ||
|
||
// Using the new .NET 9 Index method. | ||
foreach ((int index, Person person) in persons.Index()) | ||
{ | ||
Console.WriteLine($"Index: {index}, Person:{person}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters