File tree 4 files changed +30
-15
lines changed
4 files changed +30
-15
lines changed Original file line number Diff line number Diff line change 1
1
// Extension types
2
2
// https://github.com/dotnet/csharplang/blob/main/proposals/extensions.md
3
3
4
+ Console . WriteLine ( "Test 1" ) ;
5
+
4
6
// C# 3.0 Version
5
7
public static class StringExtensionsCsharp3
6
8
{
@@ -11,6 +13,7 @@ public static bool IsNotNullOrEmpty(this string text)
11
13
}
12
14
13
15
// C# 13 Version
16
+ /*
14
17
implicit extension StringExtensionsCsharp13 for string
15
18
{
16
19
public bool IsNotNullOrEmptyV1()
@@ -34,3 +37,4 @@ public bool this[int index]
34
37
35
38
static ulong Mask(int index) => `ul << index;
36
39
}
40
+ */
Original file line number Diff line number Diff line change 6
6
<ImplicitUsings >enable</ImplicitUsings >
7
7
<Nullable >enable</Nullable >
8
8
<LangVersion >preview</LangVersion >
9
+ <StartupObject >NewLINQMethodsCsharp13.Program</StartupObject >
9
10
</PropertyGroup >
10
11
11
12
</Project >
Original file line number Diff line number Diff line change 1
- public record Person ( string name ) ;
2
-
3
- var persons = new List < Person > ( ) { new ( "p1" ) , new ( "p2" ) } ;
4
-
5
- // Using a for loop
6
- for ( int i = 0 ; i < persons . Count ; i ++ )
1
+ namespace NewLINQMethodsCsharp13
7
2
{
8
- var person = persons [ i ] ;
9
- Console . WriteLine ( $ "Index: { i } , Person:{ person } ") ;
10
- }
3
+ public record Person ( string name ) ;
4
+ public class Program
5
+ {
6
+ public static void Main ( string [ ] args )
7
+ {
8
+ var persons = new List < Person > ( ) { new ( "p1" ) , new ( "p2" ) } ;
11
9
12
- // Using the new .NET 9 Index method.
13
- foreach ( ( int index , Person person ) in persons . Index ( ) )
14
- {
15
- Console . WriteLine ( $ "Index: { index } , Person:{ person } ") ;
10
+ // Using a for loop
11
+ for ( int i = 0 ; i < persons . Count ; i ++ )
12
+ {
13
+ var person = persons [ i ] ;
14
+ Console . WriteLine ( $ "Index: { i } , Person:{ person } ") ;
15
+ }
16
+
17
+ // Using the new .NET 9 Index method.
18
+ foreach ( ( int index , Person person ) in persons . Index ( ) )
19
+ {
20
+ Console . WriteLine ( $ "Index: { index } , Person:{ person } ") ;
21
+ }
22
+ }
23
+ }
16
24
}
Original file line number Diff line number Diff line change 13
13
// What is the difference between Task.Run() and Task.Factory.StartNew()
14
14
// https://stackoverflow.com/questions/38423472/what-is-the-difference-between-task-run-and-task-factory-startnew
15
15
16
+ #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
16
17
Task . Factory . StartNew ( ( ) =>
17
18
{
18
19
Singleton instance2 = Singleton . Instance ;
30
31
Console . WriteLine ( instance2 . CurrentDateTime ) ;
31
32
} , TaskCreationOptions . AttachedToParent ) . Start ( ) ;
32
33
} ) ;
34
+ #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
33
35
34
36
35
37
public class Singleton
36
38
{
37
- private readonly System . Threading . Lock _lock = new ( ) ;
39
+ private static readonly System . Threading . Lock _lock = new ( ) ;
38
40
private static Singleton instance = null ;
39
41
public DateTime CurrentDateTime => _currentDateTime ;
40
42
private DateTime _currentDateTime ;
@@ -43,7 +45,7 @@ public static Singleton Instance
43
45
{
44
46
get
45
47
{
46
- if ( _lock )
48
+ lock ( _lock )
47
49
{
48
50
// Logical patterns Csharp-9
49
51
// https://devblogs.microsoft.com/dotnet/c-9-0-on-the-record/#logical-patterns
You can’t perform that action at this time.
0 commit comments