-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSum.cs
More file actions
59 lines (51 loc) · 1.17 KB
/
Sum.cs
File metadata and controls
59 lines (51 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
public class WorkWithSum
{
public static int SumBlock()
{
int[] array = Enumerable.Range(0, 1000).ToArray();
// while(true)
// {
int[] copy = new int[50];
Array.Copy(array, 500, copy, 0, 2);
Console.WriteLine(string.Join(", ", copy));
return Sum(copy);
// }
}
public static int Sum(int[] array)
{
int sum = 0;
foreach (int i in array)
{
sum += i;
}
return sum;
}
public static int Sum(int[] array, int offset, int length)
{
int sum = 0;
for (int i = offset; i < offset + length; i++)
{
sum += array[i];
}
return sum;
}
public static int Sum(List<int> list, int offset, int length)
{
int sum = 0;
for (int i = offset; i < offset + length; i++)
{
sum += list[i];
}
return sum;
}
public static int Sum(Span<int> span)
{
int sum = 0;
// for (int i = 0; i < span.Length; i++)
// {
// sum += span[i];
// }
foreach (int el in span) sum += el;
return sum;
}
}