I have declared a variable as underscore character _ like below and the compiler able to execute the code smoothly.
int _ = 10;
_ += 10;
onsole.WriteLine(_);
But, the compiler is not detecting the variable named as underscore character _ for a Deconstruction syntax shown below.
(string _, int age) = new Student("Vimal", "Heaven", 20);
At the same time, compiler and Visual Studio intellisense detect the variable named as underscore _ for another syntax shown below.
var student = new Student("Vimal", "Heaven", 20);
(string _, int age) details = student.GetDetails();
Console.WriteLine(details._);
I understand that nobody use underscore character to name a variable. Why compiler is inconsistent in handling the underscore _ character?
I am not discussing about the C# discards here.
The Student class referred in the sample.
public class Student
{
public string Name { get; set; }
public string Address { get; set; }
public int Age { get; set; }
public Student(string name, string address, int age = 0) => (Name, Address, Age) = (name, address, age);
public void Deconstruct(out string name, out int age) => (name, age) = (Name, Age);
public (string, int) GetDetails() => (Name, Age);
}