Skip to content

Commit

Permalink
Params Collections (csharp-13)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimatay committed Jun 14, 2024
1 parent dc0d2ba commit 4194c77
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CsharpLangExamples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DefaultLambdaParameters", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalFunctionsCsharp7", "LocalFunctionsCsharp7\LocalFunctionsCsharp7.csproj", "{4E00431D-E60B-4866-A78F-091048B911F8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParamsCollections", "ParamsCollections\ParamsCollections.csproj", "{5676D9D9-B99F-4B18-B6C6-2C0353655B07}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -183,6 +185,10 @@ Global
{4E00431D-E60B-4866-A78F-091048B911F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E00431D-E60B-4866-A78F-091048B911F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E00431D-E60B-4866-A78F-091048B911F8}.Release|Any CPU.Build.0 = Release|Any CPU
{5676D9D9-B99F-4B18-B6C6-2C0353655B07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5676D9D9-B99F-4B18-B6C6-2C0353655B07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5676D9D9-B99F-4B18-B6C6-2C0353655B07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5676D9D9-B99F-4B18-B6C6-2C0353655B07}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
11 changes: 11 additions & 0 deletions ParamsCollections/ParamsCollections.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
</PropertyGroup>

</Project>
34 changes: 34 additions & 0 deletions ParamsCollections/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// See https://aka.ms/new-console-template for more information
// Console.WriteLine("Hello, World!");

// https://github.com/dotnet/csharplang/issues/7700
// https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/collection-expressions

void PrintNumbers(params List<int>[] numbersLists)
{
foreach(var numbers in numbersLists)
{
foreach(var number in numbers)
{
Console.WriteLine(number);
}
}
}


PrintNumbers(new List<int> {1, 2, 3}, new List<int> {4, 5, 6}, new List<int> {7, 8, 9});
/*
1
2
3
4
5
6
7
8
9
*/

int Sum(params ReadOnlySpan<int> values) => values.ToArray().Sum(x=>x);

Console.WriteLine(Sum(1, 2, 3,4,5,6,7,8,9,10)); // 55
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Examples of C# programming, with the goal of tracking and staying up-to-date wit

## Version History

* C# 13
* [Params Collections](ParamsCollections/)

* C# 12
* [Primary constructors](PrimaryConstructors/)
* [Default values for parameters in lambda expressions](DefaultLambdaParameters/)
Expand Down

0 comments on commit 4194c77

Please sign in to comment.