Skip to content

Commit 56fb30f

Browse files
committed
Add cross-language extra examples and harden C# smoke
1 parent 611cc34 commit 56fb30f

56 files changed

Lines changed: 1816 additions & 4 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

languages/csharp/01-foundations/arrays-and-vectors/example/arrays-and-vectors-example.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>disable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
78
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="main.cs" />
11+
</ItemGroup>
812
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>disable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="vector-filter.cs" />
11+
</ItemGroup>
12+
</Project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// This extra example extends arrays-and-vectors with a focused filtering task.
2+
// Example purpose: isolate list building and threshold-based filtering.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
7+
class Program
8+
{
9+
static void Main()
10+
{
11+
Console.Write("How many numbers? ");
12+
if (!int.TryParse(Console.ReadLine(), out int count) || count <= 0)
13+
{
14+
Console.WriteLine("Please enter a positive count.");
15+
return;
16+
}
17+
18+
List<int> values = new List<int>(count);
19+
for (int index = 0; index < count; index++)
20+
{
21+
Console.Write($"Value {index + 1}: ");
22+
if (!int.TryParse(Console.ReadLine(), out int value))
23+
{
24+
Console.WriteLine("Please enter valid integers only.");
25+
return;
26+
}
27+
28+
values.Add(value);
29+
}
30+
31+
Console.Write("Filter values greater than or equal to: ");
32+
if (!int.TryParse(Console.ReadLine(), out int threshold))
33+
{
34+
Console.WriteLine("Please enter a valid threshold.");
35+
return;
36+
}
37+
38+
List<int> filtered = values.FindAll(value => value >= threshold);
39+
if (filtered.Count > 0)
40+
{
41+
Console.WriteLine("Filtered values: " + string.Join(", ", filtered));
42+
}
43+
else
44+
{
45+
Console.WriteLine("Filtered values: none");
46+
}
47+
}
48+
}

languages/csharp/01-foundations/control-flow/example/control-flow-example.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>disable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
78
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="main.cs" />
11+
</ItemGroup>
812
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>disable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="menu-loop.cs" />
11+
</ItemGroup>
12+
</Project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// This extra example extends control-flow with a menu-driven loop.
2+
// Example purpose: show repeated branching and state updates.
3+
4+
using System;
5+
6+
class Program
7+
{
8+
static void Main()
9+
{
10+
int currentSum = 0;
11+
12+
while (true)
13+
{
14+
Console.WriteLine("\nMenu");
15+
Console.WriteLine("1) Add number to sum");
16+
Console.WriteLine("2) Show current sum");
17+
Console.WriteLine("3) Reset sum");
18+
Console.WriteLine("4) Exit");
19+
Console.Write("Choose an option: ");
20+
21+
string? choice = Console.ReadLine();
22+
switch (choice)
23+
{
24+
case "1":
25+
Console.Write("Enter a number: ");
26+
if (!int.TryParse(Console.ReadLine(), out int number))
27+
{
28+
Console.WriteLine("Invalid number. Try again.");
29+
continue;
30+
}
31+
32+
currentSum += number;
33+
Console.WriteLine($"Added. New sum is {currentSum}.");
34+
break;
35+
case "2":
36+
Console.WriteLine($"Current sum: {currentSum}");
37+
break;
38+
case "3":
39+
currentSum = 0;
40+
Console.WriteLine("Sum reset to 0.");
41+
break;
42+
case "4":
43+
Console.WriteLine("Goodbye.");
44+
return;
45+
default:
46+
Console.WriteLine("Invalid option. Try again.");
47+
break;
48+
}
49+
}
50+
}
51+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>disable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="function-overload-basics.cs" />
11+
</ItemGroup>
12+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This extra example extends functions with overload-style dispatch.
2+
// Example purpose: show one method name handling multiple value types.
3+
4+
using System;
5+
6+
class Program
7+
{
8+
static void PrintValue(int value)
9+
{
10+
Console.WriteLine($"Integer value: {value}");
11+
}
12+
13+
static void PrintValue(double value)
14+
{
15+
Console.WriteLine($"Double value: {value}");
16+
}
17+
18+
static void PrintValue(string value)
19+
{
20+
Console.WriteLine($"String value: {value}");
21+
}
22+
23+
static void Main()
24+
{
25+
PrintValue(42);
26+
PrintValue(3.14159);
27+
PrintValue("Hello from function overloads");
28+
}
29+
}

languages/csharp/01-foundations/functions/example/functions-example.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>disable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
78
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="main.cs" />
11+
</ItemGroup>
812
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>disable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="string-clean-and-tokenize.cs" />
11+
</ItemGroup>
12+
</Project>

0 commit comments

Comments
 (0)