-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path101RefTypes.cs
More file actions
32 lines (28 loc) · 855 Bytes
/
101RefTypes.cs
File metadata and controls
32 lines (28 loc) · 855 Bytes
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
using System;
namespace CSharp7Console
{
public class RefTypes
{
//Not available in c# 7 yet
/*
public ref int Find(int number, int[] numbers)
{
for (int i = 0; i < numbers.Length; i++)
{
if (numbers[i] == number)
{
return ref numbers[i]; // return the storage location, not the value
}
}
throw new IndexOutOfRangeException($"{nameof(number)} not found");
}
int[] array = { 1, 15, -39, 0, 7, 14, -12 };
public void RefTypesExample()
{
ref int place = ref Find(7, array); // aliases 7's place in the array
place = 9; // replaces 7 with 9 in the array
Console.WriteLine(array[4]); // prints 9
}
*/
}
}