格式化全名绝对最快的方法是什么?中间名和后缀可能为空或为空?
string fullname = string.Format("{0} {1} {2} {3}",
FName,
MI,
LName,
Suffix);
这样做的问题是,如果 MI 或后缀为空,那么我有两个空格。
我可以用这个进行第二次传递:
fullname = fullname.Replace(" ", " ");
或者我可以用这样的东西制作字符串:
string fullname = string.Format("{0}{1} {2}{3}",
FName,
string.IsNullOrEmpty(MI) ? "" : " " + MI,
LName,
string.IsNullOrEmpty(Suffix) ? "" : " " + Suffix);
有更好的选择吗? 最快最重要。