Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有名单:
IEnumerable<Name> names; names = n.GetNames(abc);
它的列表如下:Ken,John,Sam,...我希望它显示如下:'Ken','John','Sam',...
我试过这个: string s = string.Join("',", names);但它给出的结果如下:Ken',John',Sam',......
string s = string.Join("',", names);
有没有办法在单行代码中在这些名称前面添加“'”?
试试这个。
string s = string.Join(",", names.Select(s => string.Format("'{0}'", s)).ToArray());
我想你几乎在那里:
string s = "'" + string.Join("','", names) + "'";