-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
69 lines (56 loc) · 1.64 KB
/
Program.cs
File metadata and controls
69 lines (56 loc) · 1.64 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
60
61
62
63
64
65
66
67
68
69
var a = Enumerable.Range(1, 5).ToArray();
// Console.WriteLine(WorkWithSum.Sum(a, 2, 2));
Span<int> s = new Span<int>(a, 2, 2);
// Console.WriteLine(WorkWithSum.Sum(s));
// unsafe
// {
// int* ptr = stackalloc int[2000];
// WorkWithSum.Sum(new Span<int>(ptr, 1000));
// }
// string st = string.Create(34, Guid.NewGuid(), (span, s) =>
// {
// Console.WriteLine(span.ToString());
// span[0] = 'M';
// span[1] = 'T';
// span[2] = 'Z';
// Console.WriteLine(s);
// Console.WriteLine(span.ToString());
// s.TryFormat(span[2..], out _, "N");
// Console.WriteLine(span.ToString());
// });
// Console.WriteLine(st.Length);
// Console.WriteLine("X"+st+"X");
// int i = 20;
// Console.WriteLine(Use(ref i));
// Console.WriteLine(i);
// static ref int Use(ref int myInt)
// {
// myInt = 12;
// return ref myInt;
// }
// int i = 42;
// var span = new MySpan<int>(ref i);
// span[0]++;
// Console.WriteLine(i); // 43
int[] arr = [9,8,7];
var sp2 = new MySpan<int>(arr);
// int i = -3;
// long j = -4294967296;
// Console.WriteLine((uint) i);
// Console.WriteLine((uint) j);
// Console.WriteLine(int.MaxValue);
// Console.WriteLine((long)int.MaxValue * 2);
// Console.WriteLine(sp2[1]);
// Console.WriteLine(sp2[2]);
// Console.WriteLine(sp2[3]);
// Console.WriteLine(sp2[4]);
// MySpan<char> myWords = new MySpan<char>("Hey Gilbert".ToCharArray());
// while(myWords.Length > 0)
// {
// Console.WriteLine(myWords[0]);
// myWords ;= myWords.Slice(1);
// }
MyReadonlySpan<string> namesSpan = new(["Gilbert", "Jane", "Emily"]);
Console.WriteLine(namesSpan[1]);
// namesSpan[2] = "Peter";
Console.WriteLine(namesSpan[2]);