草庐IT

foo_basic_string

全部标签

C# HashSet<string> 到单个字符串

我有一个HashSet定期添加。我想要做的是在不执行foreach循环的情况下将整个HashSet转换为字符串。有人有例子吗? 最佳答案 无论您是否显式编写内容,您都将遍历内容。然而,如果没有明确的写作,如果你说“cast”是指“concatenate”,你会这样写stringoutput=string.Join("",yourSet);//.NET4.0stringoutput=string.Join("",yourSet.ToArray());//.NET3.5 关于C#HashSe

c# - ICollection<string> 到 string[]

我有一个ICollection类型的对象.转换为string[]的最佳方式是什么?.如何在.NET2中完成此操作?如何在更高版本的C#中更清晰地完成此操作,或许在C#3中使用LINQ? 最佳答案 您可以使用以下代码片段将其转换为普通数组:string[]array=newstring[collection.Count];collection.CopyTo(array,0);这应该可以完成工作:) 关于c#-ICollection到string[],我们在StackOverflow上找到一

C# Linq - 无法将 IEnumerable<string> 隐式转换为 List<string>

我有一个这样定义的列表:publicListAttachmentURLS;我正在像这样向列表中添加项目:instruction.AttachmentURLS=curItem.Attributes["ows_Attachments"].Value.Split(';').ToList().Where(Attachment=>!String.IsNullOrEmpty(Attachment));但我收到此错误:无法将IEnumerable隐式转换为列表我做错了什么? 最佳答案 Where方法返回IEnumerable.尝试添加.ToLis

c# - : this(foo) syntax in C# constructors?

时不时地,我会遇到以前见过但从未使用过的语法。这是其中一个时代。谁能解释一下C#构造方法后面的“:this”或“:base”的用途?例如:publicMyClass(SomeArgarg):this(newSomethingElse(),arg){}我的直觉是它用于将默认参数映射到另一个构造方法。 最佳答案 你基本上是对的。this()在当前实例上调用构造函数,base()在当前实例上调用父类(superclass)型的构造函数。它们通常用于处理构造函数重载,因此您可以添加额外的选项而无需将内容分解为单独的方法。

c# - 如何将 XML 转换为 List<string> 或 String[]?

如何将以下XML转换为List或String[]:12 最佳答案 听起来您更多的是在解析之后而不是完整的XML序列化/反序列化。如果您可以使用LINQtoXML,这将非常简单:usingSystem;usingSystem.Linq;usingSystem.Xml.Linq;publicclassTest{staticvoidMain(){stringxml="12";XDocumentdoc=XDocument.Parse(xml);varlist=doc.Root.Elements("id").Select(element=>e

c# - 如何将 string[] 转换为 ArrayList?

我有一个字符串数组。如何将其转换为System.Collections.ArrayList? 最佳答案 string[]myStringArray=newstring[2];myStringArray[0]="G";myStringArray[1]="L";ArrayListmyArrayList=newArrayList();myArrayList.AddRange(myStringArray); 关于c#-如何将string[]转换为ArrayList?,我们在StackOverfl

c# - 如何在一行 C# 3.0 中将 object[] 转换为 List<string>?

好吧,我放弃了,你如何在一行中做到这一点?publicobjectConvert(object[]values,TypetargetType,objectparameter,System.Globalization.CultureInfoculture){//Listfields=values.ToList();//Listfields=valuesasList;//Listfields=(List)values;Listfields=newList();foreach(objectvalueinvalues){fields.Add(value.ToString());}//proce

c# - C# 代码是否比 Visual Basic.NET 代码更快?

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭5年前。ImprovethisquestionC#代码是否比VisualBasic.NET代码更快,还是一个神话?

c# - 这段代码怎么可能: "ArgumentOutOfRangeException: startIndex cannot be larger than length of string"?

我的C#代码中有以下方法://////Removesthefirst(leftmost)occurenceofafroma.//////Thestringtoremovethefrom.Cannotbenull.///Thesubstringtolookforandremovefromthe.Cannotbenull.//////Therestofthe,afterthefirst(leftmost)occurenceoftheinit(ifany)hasbeenremoved.////////////Ifthedoesnotoccurwithinthe,theisreturnedin

c# - String.GetHashCode() 返回不同的值

为什么GetHashCode()为同一个字符串返回不同的值?我无法描述如何复制它,但请相信这不是一个恶作剧,并且以下两行来self的watch窗口在两个不同的时间:"DDD.Events.Application.ApplicationReferenceCreated".GetHashCode()-1386151123int"DDD.Events.Application.ApplicationReferenceCreated".GetHashCode()1858139950int怎么会这样?我不知道这是否有帮助,但我在VS2010中运行.NET4.0,并且正在调试NServiceBus应