silentthread2k
asked on
Implicitly and Explicitly calling default constructor of a class in C# 3.0
Hi, I have 2 questions about C# 3.0.......
What is the difference between
"implicitly calling the default constructor"
and
"explicitly calling the default constructor"
of a class?
Any advantages or reason to use a particular one?
(see attached code snippet)
What is the difference between
"implicitly calling the default constructor"
and
"explicitly calling the default constructor"
of a class?
Any advantages or reason to use a particular one?
(see attached code snippet)
class Program
{
static void Main(string[] args)
{
// example 1, old school
MyClass mclass1 = new MyClass();
Console.WriteLine(mclass1.mystring);
//example 2, new with C# 3.0, implicitly calls the classes default constructor.
MyClass mclass2 = new MyClass { mystring = "test2" };
Console.WriteLine(mclass2.mystring);
//example 2, new with C# 3.0, explicitly calls the classes default constructor.
MyClass mclass3 = new MyClass () { mystring = "test3" };
Console.WriteLine(mclass3.mystring);
Console.ReadLine();
}
}
class MyClass
{
public string mystring { get; set; }
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What do does "implicitly" and "explicitly" mean in the context it is being used.