-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram5_AsyncStream.cs
More file actions
48 lines (45 loc) · 1.39 KB
/
Copy pathProgram5_AsyncStream.cs
File metadata and controls
48 lines (45 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
namespace ConsoleApp5_Asyn_Stream
{
/* exmaple 5
* pj92singh
* Prabhjit Singh
*
* using sutdent class again but with Async Streams
*/
public class Student
{
//either intalize or use nullable refernce types
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string? Email { get; set; }
public string? GPA { get; set; }
}
class Program
{
async static void Main(string[] args)
{
//await is needed
//for something that is using async streams
await foreach(var student in GetStudentAsync())
{
Console.WriteLine($"{Student.FirstName} {Student.LastName}");
}
Console.ReadKey();
}
async static IAsyncEnumerable<Student> GetStudentAsync()
{
var list = new List<Student>()
{
new Student() {FirstName = "John", LastName = "Doe", Email = "john.doe@test.com", GPA = 2.98},
new Student(){FirstName = "Bob", LastName = "Olsn", Email = "bob.o@test.com", GPA = 3.22}
};
foreach(var Student in list)
{
await Task.Delay(3000);
yield return Student;
//returns the stream of students
}
}
}
}