Skip to content

Commit bcb3b45

Browse files
author
ahotko
committed
Minor update in LINQ samples
1 parent d782f38 commit bcb3b45

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CSharp Code Samples/CodeSamples/CodeSamples.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<Compile Include="Classes\ConstructorChainingSample.cs" />
6060
<Compile Include="Attributes\DebuggingSample.cs" />
6161
<Compile Include="Classes\ExtensionMethodsSample.cs" />
62+
<Compile Include="Constants.cs" />
6263
<Compile Include="ISampleExecute.cs" />
6364
<Compile Include="MultiThreading\BackgroundWorkerSample.cs" />
6465
<Compile Include="Patterns\Behavioral\ObserverPattern.cs" />

CSharp Code Samples/CodeSamples/Useful/LinqSample.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class LinqSample : SampleExecute
2626
{
2727
List<LinqSampleClass> _sampleList = new List<LinqSampleClass>();
2828

29-
private void PrepareList()
29+
private void PrepareList(int sampleCount)
3030
{
3131
#region Source Collections
3232
var names = new Collection<string>() { "Sasha", "Ria", "Kaseem", "Eve", "Keegan", "Giacomo", "Alana", "Katelyn",
@@ -48,6 +48,10 @@ private void PrepareList()
4848
var places = new Collection<string>() { "Rio Verde", "Sherborne", "Bolano", "Waver", "Sclayn" };
4949
#endregion
5050

51+
int maxAvailableSamples = names.Count * lastNames.Count * places.Count;
52+
if (sampleCount > maxAvailableSamples)
53+
throw new ArgumentOutOfRangeException("sampleCount", $"Requested sample count ({sampleCount}) too big. Max available count is {maxAvailableSamples}");
54+
5155
#region Long list of names
5256
_sampleList = new List<LinqSampleClass>();
5357
int count = 0;
@@ -68,13 +72,13 @@ private void PrepareList()
6872
_sampleList.Add(sample);
6973
count++;
7074
}
71-
} while (count < Constants.Linq.MaxSamples);
75+
} while (count < sampleCount);
7276
#endregion
7377
}
7478

7579
public LinqSample()
7680
{
77-
PrepareList();
81+
PrepareList(Constants.Linq.MaxSamples);
7882
}
7983

8084
private void SumAgeSimple()

0 commit comments

Comments
 (0)