When initializing in C# constructors what's better: initializer lists or assignment?
Posted
by user260197
on Stack Overflow
See other posts from Stack Overflow
or by user260197
Published on 2010-03-12T19:19:14Z
Indexed on
2010/03/12
19:27 UTC
Read the original article
Hit count: 197
Class A uses an initializer list to set the member to the paramter value, while Class B uses assignment within the constructor's body.
Can anyone give any reason to prefer one over the other as long as I'm consistent?
class A
{
String _filename;
A(String filename) : _filename(filename)
{
}
}
class B
{
String _filename;
B(String filename)
{
_filename = filename;
}
}
© Stack Overflow or respective owner