我加入了一个字符串加载来制作一个超级字符串,但如果一个为空,我需要忽略一个参数.目前我无法想到如何做到这一点,除了在单独的if语句中包含所有参数.帮助请:
这里的代码
public void LinkBuilder(string baselink,string sharedkey,string service,string period,string bulletintype,string includeresults,string includemap,string username,string password) { sharedkey = "&" + sharedkey; service = "&" + service; period = "&" + period; bulletintype = "&" + bulletintype; includeresults = "&" + includeresults; includemap = "&" + includemap; username= "&" + username; password = "&" + password; string completeLink = sharedkey + service + period + bulletintype + includeresults + includemap + username + password;
不知道如何解决这个问题.
解决方法
我真的会这样重构它:
public void LinkBuilder(params string[] links) { string completeLink = String.Join("&",links.Where(x=>!String.IsNullOrEmpty(x))); }