1
1
using System . Net ;
2
- using System . Threading ;
3
2
using System . Runtime . CompilerServices ;
4
3
5
4
record Command ( string Option , string Text , Action Action ) ;
6
5
7
6
class Program
8
7
{
9
8
private static readonly Command [ ] commands =
10
- {
9
+ [
11
10
new ( "-async" , nameof ( CallerWithAsync ) , CallerWithAsync ) ,
12
11
new ( "-awaiter" , nameof ( CallerWithAwaiter ) , CallerWithAwaiter ) ,
13
12
new ( "-cont" , nameof ( CallerWithContinuationTask ) , CallerWithContinuationTask ) ,
@@ -16,7 +15,7 @@ class Program
16
15
new ( "-comb2" , nameof ( MultipleAsyncMethodsWithCombinators2 ) , MultipleAsyncMethodsWithCombinators2 ) ,
17
16
new ( "-val" , nameof ( UseValueTask ) , UseValueTask ) ,
18
17
new ( "-casync" , nameof ( ConvertingAsyncPattern ) , ConvertingAsyncPattern )
19
- } ;
18
+ ] ;
20
19
21
20
static void Main ( string [ ] args )
22
21
{
@@ -70,7 +69,7 @@ private static async void ConvertingAsyncPattern()
70
69
Stream stream = response . GetResponseStream ( ) ;
71
70
using StreamReader reader = new ( stream ) ;
72
71
string content = reader . ReadToEnd ( ) ;
73
- Console . WriteLine ( content . Substring ( 0 , 100 ) ) ;
72
+ Console . WriteLine ( content [ .. 100 ] ) ;
74
73
75
74
#pragma warning restore SYSLIB0014
76
75
}
@@ -141,7 +140,7 @@ static Task<string> GreetingAsync(string name) =>
141
140
return Greeting ( name ) ;
142
141
} ) ;
143
142
144
- private readonly static Dictionary < string , string > names = new ( ) ;
143
+ private readonly static Dictionary < string , string > names = [ ] ;
145
144
146
145
static async ValueTask < string > GreetingValueTaskAsync ( string name )
147
146
{
@@ -189,6 +188,6 @@ public static void TraceThreadAndTask(string info)
189
188
{
190
189
string taskInfo = Task . CurrentId == null ? "no task" : "task " + Task . CurrentId ;
191
190
192
- Console . WriteLine ( $ "{ info } in thread { Thread . CurrentThread . ManagedThreadId } and { taskInfo } ") ;
191
+ Console . WriteLine ( $ "{ info } in thread { Environment . CurrentManagedThreadId } and { taskInfo } ") ;
193
192
}
194
193
}
0 commit comments