public string BuildMsg(bool takeFirstPath)
{
StringBuilder msg = new StringBuilder();
if (takeFirstPath)
{
msg.Append("A problem occurred.");
msg.Append("\nThis is a problem.");
msg.Append("imagine much more text");
}
else
{
msg.Append("This path is not so bad.");
msg.Append("\nIt is only a minor inconvenience.");
msg.Append("Add more detailed diagnostics here.");
}
return msg.ToString();
} public string BuildMsg2(bool takeFirstPath)
{
if (takeFirstPath)
{
return FirstPath();
}
else
{
return SecondPath();
}
}public class MyClass2
{
// declare the collection, and initialize it.
private List<string> labels = new List<string>();
MyClass2()
{
}
MyClass2(int size)
{
labels = new List<string>(size);
}
}public class MyClass2
{
// declare the collection, and initialize it.
private List<string> labels;
MyClass2()
{
labels = new List<string>();
}
MyClass2(int size)
{
labels = new List<string>();
labels = new List<string>(size);
}
} public class MyClass
{
// collection of data
private List<ImportantData> coll;
// Name of the instance:
private string name;
public MyClass() :
this(0, "")
{
}
public MyClass(int initialCount) :
this(initialCount, string.Empty)
{
}
public MyClass(int initialCount, string name)
{
coll = (initialCount > 0) ?
new List<ImportantData>(initialCount) :
new List<ImportantData>();
this.name = name;
}
} public class MyClass
{
// collection of data
private List<ImportantData> coll;
// Name of the instance:
private string name;
public MyClass()
{
commonConstructor(0, "");
}
public MyClass(int initialCount)
{
commonConstructor(initialCount, "");
}
public MyClass(int initialCount, string Name)
{
commonConstructor(initialCount, Name);
}
private void commonConstructor(int count,
string name)
{
coll = (count > 0) ?
new List<ImportantData>(count) :
new List<ImportantData>();
this.name = name;
}
} public class MyClass
{
// collection of data
private List<ImportantData> coll;
// Name of the instance:
private string name;
public MyClass()
{
object();
commonConstructor(0, "");
}
public MyClass(int initialCount)
{
object();
commonConstructor(initialCount, "");
}
public MyClass(int initialCount, string Name)
{
object();
commonConstructor(initialCount, Name);
}
private void commonConstructor(int count,
string name)
{
coll = (count > 0) ?
new List<ImportantData>(count) :
new List<ImportantData>();
this.name = name;
}
}改善C#编程的50个建议(11-15),布布扣,bubuko.com
原文:http://blog.csdn.net/edcvf3/article/details/22149937