Skip to content

Commit d72a1bb

Browse files
Merge pull request #87 from KhanbalaRashidov/main
PROVISIONS: C# 11 Top Level Statements
2 parents a12bbfb + ab09559 commit d72a1bb

File tree

9 files changed

+165
-5
lines changed

9 files changed

+165
-5
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34112.27
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CollectionExpressions", "CollectionExpressions\CollectionExpressions.csproj", "{9F5A7B85-8125-4E91-AC65-1331914F61FB}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{9F5A7B85-8125-4E91-AC65-1331914F61FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9F5A7B85-8125-4E91-AC65-1331914F61FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9F5A7B85-8125-4E91-AC65-1331914F61FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{9F5A7B85-8125-4E91-AC65-1331914F61FB}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {2265E6A8-F934-40A2-A69B-AF59746CAAFD}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Create an array:
2+
int[] a = [1, 2, 3, 4, 5, 6, 7, 8];
3+
4+
// Create a span
5+
Span<int> b = ['a', 'b', 'c', 'd', 'e', 'f', 'h', 'i'];
6+
7+
// Create a 2 D array:
8+
int[][] twoD = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
9+
10+
// create a 2 D array from variables:
11+
int[] row0 = [1, 2, 3];
12+
int[] row1 = [4, 5, 6];
13+
int[] row2 = [7, 8, 9];
14+
int[][] twoDFromVariables = [row0, row1, row2];
15+
16+
foreach( var elements in twoDFromVariables)
17+
{
18+
foreach( var element in elements)
19+
{
20+
Console.Write($"{element}, ");
21+
}
22+
Console.WriteLine();
23+
}
24+
25+
//Create a single row array
26+
int[] single = [.. row0, .. row1, .. row2];
27+
28+
foreach (var element in single)
29+
{
30+
Console.Write($"{element}, ");
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34212.112
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrimaryConstructors", "PrimaryConstructors\PrimaryConstructors.csproj", "{2100064A-807B-4F4F-BA24-D008FDE88821}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{2100064A-807B-4F4F-BA24-D008FDE88821}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{2100064A-807B-4F4F-BA24-D008FDE88821}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{2100064A-807B-4F4F-BA24-D008FDE88821}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{2100064A-807B-4F4F-BA24-D008FDE88821}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {5AF4AE7E-BAAD-43C7-B8D6-5255C52788A7}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class NamedItem(string name)
2+
{
3+
public string Name => name;
4+
}
5+
6+
// name isn't captured in Widget.
7+
// width, height, and depth are captured as private fields
8+
public class Widget(string name, int width, int height, int depth) : NamedItem(name)
9+
{
10+
public Widget() : this("N/A", 1, 1, 1) { } // unnamed unit cube
11+
12+
public int WidthInCM => width;
13+
public int HeightInCM => height;
14+
public int DepthInCM => depth;
15+
16+
public int Volume => width * height * depth;
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Console.WriteLine("Hello World!");
2+
3+
if (args.Length > 0)
4+
{
5+
foreach (var arg in args)
6+
{
7+
Console.WriteLine(arg);
8+
}
9+
}
10+
11+
Foo();
12+
13+
int x = 3;
14+
15+
int result = AddToX(4);
16+
Console.WriteLine(result);
17+
18+
static void Foo()
19+
{
20+
Console.WriteLine("Foo");
21+
}
22+
23+
int AddToX(int y)
24+
{
25+
return x + y;
26+
}

CSharp/TopLevelStatements/TopLevelStatements.sln

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.30218.91
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34112.27
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldCSharp1", "HelloWorldCSharp1\HelloWorldCSharp1.csproj", "{34CA8BA9-CCCD-429D-83EA-1FE6F33A26EE}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWorldCSharp1", "HelloWorldCSharp1\HelloWorldCSharp1.csproj", "{34CA8BA9-CCCD-429D-83EA-1FE6F33A26EE}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldCSharp6", "HelloWorldCSharp6\HelloWorldCSharp6.csproj", "{B2AA04B3-35DF-4D59-B46C-B376EA9FF4BD}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWorldCSharp6", "HelloWorldCSharp6\HelloWorldCSharp6.csproj", "{B2AA04B3-35DF-4D59-B46C-B376EA9FF4BD}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldCSharp9", "HelloWorldCSharp9\HelloWorldCSharp9.csproj", "{D0D45342-1F45-40F9-87D7-98591D8089CA}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWorldCSharp9", "HelloWorldCSharp9\HelloWorldCSharp9.csproj", "{D0D45342-1F45-40F9-87D7-98591D8089CA}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldCSharp12", "HelloWorldCSharp12\HelloWorldCSharp12.csproj", "{6D340860-9FA6-419D-BBEF-C41436FF98A4}"
1113
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -27,6 +29,10 @@ Global
2729
{D0D45342-1F45-40F9-87D7-98591D8089CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
2830
{D0D45342-1F45-40F9-87D7-98591D8089CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
2931
{D0D45342-1F45-40F9-87D7-98591D8089CA}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{6D340860-9FA6-419D-BBEF-C41436FF98A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{6D340860-9FA6-419D-BBEF-C41436FF98A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{6D340860-9FA6-419D-BBEF-C41436FF98A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{6D340860-9FA6-419D-BBEF-C41436FF98A4}.Release|Any CPU.Build.0 = Release|Any CPU
3036
EndGlobalSection
3137
GlobalSection(SolutionProperties) = preSolution
3238
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)