As you can see in the above example the number 4878896050065380 was not readable, but in code declaration we can make this readable by
separating parts using “-”. we can use any number of “-” , and the compiler
will just ignore this when executing the program and it just gives the normal
number as shown above.
Return a reference of variable from a function and modify the referenced variableUsing C#
7.0 we can get the reference of items based on index then we can modify that
item using this reference. Code is as shown below,
- static void Main(string[] args)
- {
- int[] _numbers = { 10, 20, 30, 40, 50 };
- ref int refNumber = ref GetRefernce(_numbers,3)
- Console.WriteLine("Before changing third Value");
- Console.WriteLine(_numbers);
- refNumber = 25;
- Console.WriteLine("After changing third Value");
- Console.WriteLine(_numbers[3]);
- Console.Read();
- }
- public static ref int GetRefernce(int[] _array, int index)
- {
- return ref _array[index];
- }
Simplified Tuple
in C# 7.0, Tuple is more simplified,
In older versions of C# to use Tuple, we need to use keyword Tuple
to declare Tuple and when retrieving time we will not know which
one we are retrieving, that is we cannot give names to the variable inside Tuple,
but in C# this is all possible, no need to use keyword Tuple to
declare Tuple and we can give names to the variables
Example as shown below
- static void Main(string[] args)
- {
- Tuple<int, string> ob = new Tuple<int, string>(100, "Ravi");
- Console.WriteLine("Employee Name: "+ob.Item2);
-
- (int, string) ob1 = (20, "Ravi");
- Console.WriteLine("Employee Name: " + ob1.Item2);
-
- (int id, string name) ob2 = (20, "Ravi");
- Console.WriteLine("Employee Name: " + ob2.name);
-
- var ob3 = (Empid:20, EmployeeName: "Ravi");
- Console.WriteLine("Employee Name: " + ob3.EmployeeName);
- Console.Read();
- }