Answers for "assign pulic variable while instantiate"

0

assign pulic variable while instantiate

This code creates an instance of Values and initializes the two properties.

class Program
{
    static void Main(string[] args)
    {
        var values = new Values();
        values.A = "A";
        values.B = "B";
    }
}

This can be shortened like so:

class Program
{
    static void Main(string[] args)
    {
        var values = new Values { A = "A", B = "B" };
    }
}

This reduces the verbosity of the code and often makes it more readable.
Posted by: Guest on May-05-2021

Code answers related to "assign pulic variable while instantiate"

Browse Popular Code Answers by Language