草庐IT

UTF8ToString

全部标签

c# - 为什么 object.ToString() 存在?

IStringable接口(interface)不是更优雅、更整洁吗?谁需要返回给我们的这个Type.FullName对象?编辑:每个人都在问为什么我认为它更优雅..好吧,就像那样,对象将具有CompareTo方法,而不是IComparable,默认情况下会抛出异常或返回0。有些对象不能也不应该描述为字符串。对象同样可以返回string.Empty。Type.FullName只是一个任意选择..而对于Console.Write(object)等方法,我认为应该是:Write(IStringable)。但是,如果您将WriteLine用于除字符串以外的任何内容(或者它的ToString很

c# - 为什么 TimeSpan.ToString() 需要转义分隔符?

您可以像这样为DateTime对象指定自定义格式:DateTime.Now.ToString("HH:mm:ss");//19:55:23但是当我尝试对TimeSpan对象使用相同的格式时,如下所示:DateTime.Now.TimeOfDay.ToString("HH:mm:ss");我收到“输入字符串的格式不正确。”异常。事实证明,解决方案是您需要像"HH\\:mm\\:ss"那样对':'字符进行转义。请注意,这里有一个双反斜杠,因为如果您只指定一个,它会破坏字符串,因此您也需要转义那个。问题是,.NETFramework开发人员为什么要这样做?必须有一个肯定的理由。为什么我们不能

c# - LINQ Guid toString()

嗨,这看起来应该可行,fromsomethingincollectionofsomestuffselectnewSelectListItem(){Text=something.Name,Value=something.SomeGuid.ToString(),Selected=false};当我尝试这样做时它不起作用给我错误LINQtoEntitiesdoesnotrecognizethemethod'System.StringToString()'method,andthismethodcannotbetranslatedintoastoreexpression.有解决办法吗?

c# - Convert.ToBase64String/Convert.FromBase64String 和 Encoding.UTF8.GetBytes/Encoding.UTF8.GetString 的区别

我目前正在学习.NET中的对称密码学。我写了一个演示如下:privatebyte[]key=Encoding.ASCII.GetBytes("abcdefgh");privatebyte[]IV=Encoding.ASCII.GetBytes("hgfedcba");privatebyte[]encrypted;publicForm1(){InitializeComponent();}privatevoidbtnEncrypt_Click(objectsender,EventArgse){this.textBox2.Text=this.Encrypt(this.textBox1.Tex

c# - 为什么在值类型上隐式调用 toString 会导致框指令

这更像是一个“想知道为什么”而不是一个特定的问题,但请看下面的代码staticvoidMain(string[]args){intval=10;Console.WriteLine("valis{0}",val);//(1)Console.WriteLine("valis{0}",val.ToString());//(2)}情况(1)输出以下ILIL_0000:nopIL_0001:ldc.i4.s10IL_0003:stloc.0IL_0004:ldstr"valis{0}"IL_0009:ldloc.0IL_000a:box[mscorlib]System.Int32IL_000f:

c# - 内容类型 text/html;响应消息的 charset=UTF-8 与绑定(bind)的内容类型不匹配(text/xml;charset=utf-8)

我使用独立应用程序创建了WCF服务并测试了WCF客户端。我能够使用InternetExplorer查看此服务,也能够在VisualStudio服务引用中查看。这是错误消息。“响应消息的内容类型text/html;charset=UTF-8与绑定(bind)的内容类型(text/xml;charset=utf-8)不匹配。”请问哪里出了问题?谢谢。 最佳答案 由于返回的内容类型是text/html,我怀疑您的调用导致了WCF之外的服务器端错误(您收到了HTML错误页面)。尝试使用网络调试代理查看响应,例如Fiddler.(根据评论编辑

c# - 复制的 NameValueCollection 的 ToString() 未输出所需的结果

我在用户控件中有一个NameValueCollection,它是这样初始化的:privateNameValueCollection_nameValues=HttpUtility.ParseQueryString(Request.QueryString.ToString());当我调用ToString()时,它会生成一个正确的查询字符串,我可以将其用于更新的url。但是,当我像这样通过其构造函数复制NameValueCollection时:varnameValues=newNameValueCollection(_nameValues);然后尝试形成一个url:varnewUrl=Str

c# - 为什么 Entity Framework 不能在 LINQ 语句中使用 ToString()?

这在LINQ-to-SQL中有效:varcustomersTest=fromcindb.Customersselectnew{Id=c.Id,Addresses=fromaindb.Addresseswherec.Id.ToString()==a.ReferenzIdselecta};foreach(varitemincustomersTest){Console.WriteLine(item.Id);}但是EntityFramework中的一个类似示例收到一条错误消息,基本上说它无法“将其转换为SQL”,这是德语中的原始错误消息:"'LINQtoEntities'erkenntdieM

c# - 是否可以禁用隐式 ToString() 调用?

我想知道是否有办法让这段代码出现编译错误:varcustomer=newSomeCustomerClass();Console.WriteLine("Customeraddress:"+customer);所以我将被迫写这样的东西:varcustomer=newSomeCustomerClass();Console.WriteLine("Customeraddress:"+customer.FormatAddress());Console.WriteLine("Customeraccounts:"+customer.FormatAccounts());如果“ToString”是一个接口

c# - 为什么 Guid.ToString ("n") 与从同一 guid 的字节数组生成的十六进制字符串不同?

考虑以下单元测试:[TestMethod]publicvoidTestByteToString(){varguid=newGuid("61772f3ae5de5f4a8577eb1003c5c054");varguidString=guid.ToString("n");varbyteString=ToHexString(guid.ToByteArray());Assert.AreEqual(guidString,byteString);}privateStringToHexString(Byte[]bytes){varhex=newStringBuilder(bytes.Length*