ValueTuple as Property of Class
A class property can store multiple values using value tuple.
class Student
{
public (string City, string Country) Address { get; set; }
}
class Demo
{
static void Main()
{
Student s = new Student();
s.Address = ("Delhi", "India");
Console.WriteLine(s.Address.City);
Console.WriteLine(s.Address.Country);
}
}
Output
Delhi
India
Another example
class Employee
{
public (string Name, int Age) Details { get; set; }
}
class Demo
{
static void Main()
{
Employee emp = new Employee
{
Details = ("Rahul", 30)
};
Console.WriteLine(emp.Details.Name);
}
}
Output
Rahul
No comments:
Post a Comment