Destructuring assignment - object properties to variables in C#

Closest thing which could help you are Tuples.

C#7 maybe will have something like this:

public (int sum, int count) Tally(IEnumerable<int> values) 
{
    var res = (sum: 0, count: 0); // infer tuple type from names and values
    foreach (var value in values) { res.sum += value; res.count++; }
    return res;
}


(var sum, var count) = Tally(myValues); // deconstruct result
Console.WriteLine($"Sum: {sum}, count: {count}"); 

Link to discussion

Right now it is not possible.


C# 7 Using Tuples. You can achieve something like this.

You can construct and destruct a Tuple. Snippet

var payLoad = (
    Username: "MHamzaRajput",
    Password: "password",
    Domain: "www.xyz.com",
    Age: "24" 
);

// Hint: You just need to follow the sequence. 

var (Username, Password, Domain, Age) = payLoad;
// or
var (username, password, _, _) = payLoad;

Console.WriteLine($"Username: {username} and Password: {password}"); 

Output

Username: MHamzaRajput and Password: password

C#6 has a lot new cool syntactic features, but unfortunately does not support deconstruction described in your question - https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6