Skip to content

Commit f5e8e56

Browse files
committedNov 21, 2024·
build and bug fix
1 parent c7773be commit f5e8e56

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed
 

‎ExtensionTypesCsharp13/Program.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Extension types
22
// https://github.com/dotnet/csharplang/blob/main/proposals/extensions.md
33

4+
Console.WriteLine("Test 1");
5+
46
// C# 3.0 Version
57
public static class StringExtensionsCsharp3
68
{
@@ -11,6 +13,7 @@ public static bool IsNotNullOrEmpty(this string text)
1113
}
1214

1315
// C# 13 Version
16+
/*
1417
implicit extension StringExtensionsCsharp13 for string
1518
{
1619
public bool IsNotNullOrEmptyV1()
@@ -34,3 +37,4 @@ public bool this[int index]
3437
3538
static ulong Mask(int index) => `ul << index;
3639
}
40+
*/

‎NewLINQMethodsCsharp13/NewLINQMethodsCsharp13.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<LangVersion>preview</LangVersion>
9+
<StartupObject>NewLINQMethodsCsharp13.Program</StartupObject>
910
</PropertyGroup>
1011

1112
</Project>

‎NewLINQMethodsCsharp13/Program.cs

+21-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
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
72
{
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") };
119

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+
}
1624
}

‎TheLockStatement/Program.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// What is the difference between Task.Run() and Task.Factory.StartNew()
1414
// https://stackoverflow.com/questions/38423472/what-is-the-difference-between-task-run-and-task-factory-startnew
1515

16+
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
1617
Task.Factory.StartNew(() =>
1718
{
1819
Singleton instance2 = Singleton.Instance;
@@ -30,11 +31,12 @@
3031
Console.WriteLine(instance2.CurrentDateTime);
3132
}, TaskCreationOptions.AttachedToParent).Start();
3233
});
34+
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
3335

3436

3537
public class Singleton
3638
{
37-
private readonly System.Threading.Lock _lock = new();
39+
private static readonly System.Threading.Lock _lock = new();
3840
private static Singleton instance = null;
3941
public DateTime CurrentDateTime => _currentDateTime;
4042
private DateTime _currentDateTime;
@@ -43,7 +45,7 @@ public static Singleton Instance
4345
{
4446
get
4547
{
46-
if (_lock)
48+
lock (_lock)
4749
{
4850
// Logical patterns Csharp-9
4951
// https://devblogs.microsoft.com/dotnet/c-9-0-on-the-record/#logical-patterns

0 commit comments

Comments
 (0)
Please sign in to comment.