I have a simple question about constructors in C#. Will these two code snippets behave the same way?
Code snippet #1:
public class foo
{
public foo(string a = null, string b = null)
{
// do testing on parameters
}
}
Code snippet #2:
public class foo
{
public foo()
{
}
public foo(string a)
{
}
public foo(string a, string b)
{
}
}
EDIT: And if I add this to the code snippet #1? It may look a really bad idea, but I'm working on refactoring a legacy code, so I'm afraid if I do sth that will cause damage to other piece of that uses that class.
public class foo
{
public foo(string a = null, string b = null)
{
if (a == null && b == null)
{
// do sth
}else if (a != null && b == null)
{
// do sth
}
if (a != null && b != null)
{
// do sth
}
else
{
}
}
}