In C# i can write
var y = new List<string>(2) { "x" , "y" };
to get a List with “x” and “y” initialized.
How do I declare a class to accept this initialization syntax?
I mean, I want to write:
var y = new MyClass(2, 3) { "x" , "y" };
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Look at section 7.6.10.3 of the C# spec:
A very simple example of this:
This will print “hello”, followed by “world” to the console.