【c# – 如何使用string.Join将Jagged数组与分隔符连接?】教程文章相关的互联网学习教程文章

c# – 如何在.net核心中执行String.Copy?【代码】

在将.net框架应用程序移植到.net核心应用程序时,有一些使用String.Copy来复制字符串.但看起来这个方法从.net core中删除了,所以你如何在.net核心应用程序中复制一个字符串,因此,它也不存在于uwp中.赋值字符串b = a;在.net核心中意味着与.netframework不同的东西? 该代码中使用了该副本:public DataDictionary(DataDictionary src):this(){this.Messages = src.Messages;this.FieldsByName = src.FieldsByName;this.FieldsByTag =...

c# – 为什么在ConfigurationManager.AppSettings [key]上调用.ToString()?【代码】

我不确定这是否会归结为意见问题,但我一直看到代码中的模式,我不明白. 在所有C#应用程序中,我一直看到表达式:System.Configuration.ConfigurationManager.AppSettings["key"].ToString()很长一段时间以来,我认为这只是我工作的一个怪癖,但我搜索了它,看起来它不仅仅是一些一次性的事情.人们做了相当多的事情,但据我所知,并没有真正谈到它. 例如,这个blog确保在AppSettings上调用.ToString(),this blog也是如此 此外,all the progr...

在c#中将string []转换为Decimal [],int [],float [] .double []【代码】

string[] txt1 = new string[]{"12","13"};this.SetValue(txt1, v => Convert.ChangeType(v, typeof(decimal[]), null));它抛出一个错误 – 对象必须实现IConvertible. 我还想要一个代码来转换string [] To Decimal [],int [],float [] .double []解决方法:您无法将字符串[]直接转换为十进制[],所有元素都必须单独转换为新类型.相反,你可以使用Array.ConvertAllstring[] txt1 = new string[]{"12","13"}; decimal[] dec1 = Array.C...

c# – Mono说’System.Net.Dns.GetHostEntry(string)’由于其保护级别而无法访问【代码】

我正在上课,其中一些例子在C#中.由于我的笔记本电脑运行Linux,我在Ubuntu上使用Mono 2.6.7. 我正在尝试编译以下代码:using System.Net.Sockets; using System.Net; using System;/// <summary> /// Example program showing simple TCP socket connections in C#.NET. /// Rather than reading and writing byte arrays, this example show /// how to use a stream reader in the client. /// TCPSocketServer is the socket ser...

c# – String.Intern有值吗?【代码】

String.Intern有一个特殊的字符串池,以后可以检索它. 有没有办法让我知道指定的字符串是从池中获取的,并且是否是新创建的?例如:string s1 = "MyTest"; string s2 = new StringBuilder().Append("My").Append("Test").ToString(); string s3 = String.Intern(s2); Console.WriteLine((Object)s2==(Object)s1); // Different references. Console.WriteLine((Object)s3==(Object)s1); // The same reference.s3 ref val取自游泳...

c#将byte转换为string并写入txt文件【代码】

我如何转换例如byte [] b = new byte [1]; b [1] = 255到字符串?我需要一个字符串变量,其值为“255”string text =“255”;然后将其存储在文本文件中?解决方法:从字节开始:byte[] b = new byte[255];string s = Encoding.UTF8.GetString(b);File.WriteAllText("myFile.txt", s);如果你从字符串开始:string x = "255";byte[] y = Encoding.UTF8.GetBytes(x);File.WriteAllBytes("myFile2.txt", y);

c# – String.Join返回×而不是时间?【代码】

这是我的代码:var signature_parameters = new SortedDictionary<string, string>() {{ "client_id", client_id },{ "timestamp", timestamp }, };var signature_base_string = string.Join("&", signature_parameters.Select(p => string.Format("{0}={1}", p.Key, p.Value))); Response.Write(signature_base_string);打印client_id = 2446782tamp = 1291723521 什么是?解决方法:您的连接是将文本& times放入正在编码为x的字符...

C#String安全替换【代码】

你有任何想法或提示如何安全地更换字符串? 例:string Example = "OK OR LOK";现在我想用true替换“OK”,用false替换“LOK”.Example = Example.Replace("OK", "true"); Example = Example.Replace("LOK", "false");现在结果是:Example =“true或Ltrue”; 结果应该是:Example =“true or false”; 我理解这个问题,但我不知道如何解决这个问题. 谢谢解决方法:您可以先替换最长的字符串,例如.用这种方法:public static string Re...

c# – string.IsNullOrEmpty(string)’有一些无效的参数【代码】

我将MVC 3.5转换为MVC2 4.0,得到一个错误’string.IsNullOrEmpty(string)’的最佳重载方法匹配有一些无效的参数这是我的代码:<% if (this.Model.VisitId == 0) { %>mustSave = true;<% } else { %>mustSave = false;<% } %><% if (String.IsNullOrEmpty(Html.ValidationSummary())) { %>dataChanged = false;<% } else { %>dataChanged = true;<% } %>提前致谢解决方法:Html.ValidationSummary()返回MvcHtmlString,而不是普通字符...

c# – Xml文件永远不应该作为String传递,如何激励?【代码】

看到如下方法签名时,我感到非常不舒服:public void foo(String theXml);如果传递一个以UTF-16 XML声明开头的String,那会是什么?在我看来,XML应该被类型化为强XML类型,如DOM树或字节数组.因此,foo应该重新声明为:public void foo(Byte[] theXml);通常,程序员会不必要地假设,当读取XML时有一定的编码.通常只是希望文件库的默认值能正确猜测. 我怎样才能激励我的同事呢? 不兼容的文档头编码声明的动机太弱了. (使用强类型或字节数...

c# – Convert.FromBase64String(…)抛出FormatException【代码】

以下代码行在IIS Express中正常运行:Convert.FromBase64String("dmVoaWNsZUlkPTE0MTM=??");但是当在我的本地IIS 8服务器上运行时,它会抛出以下异常:System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.为什么会这样?解决方法:最后两个字符“??”在base 64字符串中无效. 在这...

c# – Linq无法从’System.Collections.Generic.IEnumerable’转换为’string []’【代码】

我有这个代码的问题string.Join(",", Encoding.Unicode.GetBytes("10.10.10.11").Select(x => x.ToString("X2")));我收到了错误 无法从’System.Collections.Generic.IEnumerable< string>‘转换’string []’ 它如何导出到逗号分隔的txt框?解决方法:您可以通过调用ToArray()扩展方法将IEnumerable转换为字符串数组:string.Join(",", Encoding.Unicode.GetBytes("10.10.10.11").Select(x => x.ToString("X2")).ToArray());边注:...

c# – Convert.ToDateTime(‘Datestring’)到日期所需的dd-MM-yyyy格式【代码】

我有Date的字符串,可以是任何格式的日期,但我想将其转换为dd-MM-yyyy格式.我已经尝试了每个Convert.ToDatetime选项,它只转换为系统格式.我想要它转换dd-MM-yyyy格式. 请回复.提前致谢.解决方法:试试这个DateTime dateTime = new DateTime(); dateTime = Convert.ToDateTime(DateTime.ParseExact("YouDateString", "dd-MM-yyyy", CultureInfo.InvariantCulture));这将使用您的格式返回DateTime

c# – 用.Substring一个字一个字地读取字符串?【代码】

我得到了以下字符串字符串gen =“Action; Adventure; Drama; Horror;我尝试用.substring逐字逐句地分隔字符串:gen.Substring(gen.IndexOf(‘;’)1,gen.IndexOf(‘;’))但我的输出只是“来临”. 有帮助吗? 背景:该字符串收集已检查的复选框的名称.然后将该字符串保存在数据库中.我想读出字符串,检查另一个表单上的每个复选框.解决方法:像这样分开:public class Example {public static void Main(){String value = "Action;Adve...

c# – 为什么string.Empty比“”更推荐?

为什么string.Empty比“”更推荐? 是因为当编译器解析代码并且“来了,编译器将准备好读取字符串?但是在string.Empty中编译器甚至不准备读取字符串?解决方法:还有另一个原因. 由于它们的性质,常量是静态的,它是对某些应用程序域中所有线程共享的单个实例的引用,而文字最终会生成空字符串的N个实例. 这就是为什么建议使用string.Empty常量只读字段而不是使用空的“”字符串文字,显然,正如其他人所说,它增加了可读性. 无论如何,应该...