Skip to content

Commit

Permalink
build and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimatay committed Nov 21, 2024
1 parent c7773be commit f5e8e56
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
4 changes: 4 additions & 0 deletions ExtensionTypesCsharp13/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Extension types
// https://github.com/dotnet/csharplang/blob/main/proposals/extensions.md

Console.WriteLine("Test 1");

// C# 3.0 Version
public static class StringExtensionsCsharp3
{
Expand All @@ -11,6 +13,7 @@ public static bool IsNotNullOrEmpty(this string text)
}

// C# 13 Version
/*
implicit extension StringExtensionsCsharp13 for string
{
public bool IsNotNullOrEmptyV1()
Expand All @@ -34,3 +37,4 @@ public bool this[int index]
static ulong Mask(int index) => `ul << index;
}
*/
1 change: 1 addition & 0 deletions NewLINQMethodsCsharp13/NewLINQMethodsCsharp13.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<StartupObject>NewLINQMethodsCsharp13.Program</StartupObject>
</PropertyGroup>

</Project>
34 changes: 21 additions & 13 deletions NewLINQMethodsCsharp13/Program.cs
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}");
}
}
}
}
6 changes: 4 additions & 2 deletions TheLockStatement/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// What is the difference between Task.Run() and Task.Factory.StartNew()
// https://stackoverflow.com/questions/38423472/what-is-the-difference-between-task-run-and-task-factory-startnew

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


public class Singleton
{
private readonly System.Threading.Lock _lock = new();
private static readonly System.Threading.Lock _lock = new();
private static Singleton instance = null;
public DateTime CurrentDateTime => _currentDateTime;
private DateTime _currentDateTime;
Expand All @@ -43,7 +45,7 @@ public static Singleton Instance
{
get
{
if (_lock)
lock (_lock)
{
// Logical patterns Csharp-9
// https://devblogs.microsoft.com/dotnet/c-9-0-on-the-record/#logical-patterns
Expand Down

0 comments on commit f5e8e56

Please sign in to comment.