【c# – DataFormatString格式错误百分比】教程文章相关的互联网学习教程文章

c#-使用BinaryFormatter序列化和反序列化List>【代码】

假设我有List<object> mainList = new List<object>();它包含List<string> stringList = new List<string(); List<CustomClass> custList = new List<CustomClass>(); mainList.Add(stringList); mainList.Add(custList);序列化Stream stream; BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, mainList);反序列化Stream stream = (Stream)o; BinaryFormatter formatter = new BinaryFormatter();...

C#-String.Format()的对齐方式在涉及MessageBox时表现不同【代码】

我正在使用String.Format()格式化一些文本信息,并且它与msdn中记录的“ Console.WriteLine()”完美配合. 我的代码是这样的:StringBuilder strBuilder = new StringBuilder();strBuilder.AppendLine("Summary Information:");strBuilder.AppendFormat("{0,-10}{1,-8}{2,-10}{3,-30}{4,-7}\n", "Header1", "Header2", "Header3", "Header4", "Header5");strBuilder.AppendFormat("{0,-10}{1,-8}{2,-10}{3,-30}{4,-7}\n\n", "A", "1"...

c#-在Json.NET中使用FormatterAssemblyStyle.Simple序列化Type类型的字段【代码】

我在Unity3D中使用Json.NET(v90r1)的Net20库,并且尝试使用Json.NET序列化Type类型的字段. 我发现FormatterAssemblyStyle可以影响自动生成的类型信息,但似乎不会影响Type类型的字段.例如:using Newtonsoft.Json; using System.Runtime.Serialization.Formatters; using UnityEngine;public class Example : MonoBehaviour {void Start(){var settings = new JsonSerializerSettings() {Formatting = Formatting.Indented,TypeNameH...

结合C#String.Format格式选项【代码】

我想将我的数字格式化为带有始终可见符号的百分比值. 要将其格式化为百分比值,我可以这样做:string.Format("{0:P2}", 1.45);对于可见的迹象,我将做:string.Format("{0:+#.##;-#.##;0}", 1.45);有什么办法将两者结合起来吗?解决方法:您可能只想将%添加到custom format:string.Format("{0:+#.##%;-#.##%;0}", 1.45); // output +145%

c# – 为什么string.Format不会抛出ArgumentNullException?【代码】

根据MSDN String.Format抛出,如果format为null(非常合理),link here. 但测试说它只会在第二个参数为空的情况下执行,而不是第二个参数填充. 以下不抛出:string test = string.Format(null, "string");以下抛出抱怨第一个参数(格式):string test = string.Format(null, null);使用JustDecompile进一步挖掘源代码调用以下方法:private static string FormatHelper(IFormatProvider provider, string format, ParamsArray args){if ...

c# – 为什么我得到’System.UriFormatException:无效的URI:指定的端口无效.’使用IPv6 URI时?【代码】

为什么这个var uri = new Uri(“ftp:// 1111:2222:3333 :: 43 / testing / 1kb.zip”); 抛出这个例外?System.UriFormatException: Invalid URI: Invalid port specified. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)解决方法:从RFC 2732开始:To use a literal IPv6 address in a URL, the literal address should beenclosed in “[” and “]” characters.例如,这工作正常:var uri = new ...

c# – 如何使Label显示带有不同颜色字母的FormattedString?【代码】

我正在使用FormattedString在Xamarin.Forms上的Label上显示自定义文本.我想要实现的是改变一个或多个元素的颜色,例如:$$$$.但即使我改变颜色,Label也会显示所有具有相同颜色的美元符号:$$$$ 这是视图上的标签:<Label Text="{Binding AveragePrice, StringFormat='{0}'}" HorizontalTextAlignment="Center" />这是绑定到ViewModel上的标签文本的属性的代码public FormattedString AveragePrice {get{return new FormattedString{...

c# – 为什么String.Format歧视?【代码】

参见英文答案 > string.Format fails at runtime with array of integers 7个String.Format很乐意使用一个字符串数组,但在处理带有异常的int数组时会失败:Index (zero based) must be greater than or equal to zero and less thanthe size of the argument list.string result = null;var words = new string[] { "1", "2", "3" };result = String.Format("Count {0}{1}{2}", words); //This...

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# – 如何向String.Format参数添加前导零?【代码】

我有以下代码:string textTransDate = String.Format("{0}-{1}-{2} {3}:{4}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute);如果它们小于10,我想在月和日参数中添加前导零,我将如何实现这一目标?解决方法: string textTransDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm");更多信息: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

c# – DataFormatString格式错误百分比【代码】

我在数据库中有这个字段,它是: 数据类型:数字(7,3) 所以将允许最大数量 9999.99 进入数据库. 我把号码 10.000 进入数据库,现在我正在使用以下方法检出数据库:<asp:GridView>我指定:<asp:BoundField DataFormatString="{0:p}" />它输出 1,000.00% 这是假设的 10.00% 为什么不呢? 我也不能把< %%>服务器运行时标记到:<asp:TemplateField />为什么是这样?解决方法:百分比存储为小数,其中0 = 0%和1 = 100%.您应该将值存储为...

c# – Visual Studio 2015 Curly Brace Formatting:If,Else If,Else【代码】

我最近升级到Visual Studio 2015(更新1)并且已按照我希望的方式进行配置,但是我对花括号的格式化有点麻烦!我假设第二个代码示例是更接受的约定,但我似乎无法正确设置我的设置.我在这做错了什么? Visual Studio当前正在自动格式化我的代码,请注意else {public static string Gender(string x){if (x == "M"){return "Male";}else if (x == "F"){return "Female";}else {return "Unknown";}}我想我的代码是这样自动格式化的public ...

C# 使用BinaryFormatter序列化对象【代码】【图】

使用BinaryFormatter二进制类型。再次注意BinaryFormatter类型的两个关键方法:Serialize()和Deserialize()。 下面是Serialize()和Deserialize()介绍: Serialize():将一个对象图按字节的顺序持久化到一个指定的流。 Deserialize():将一个持久化的字节顺序转化为一个对象图。 假设已经建立了JamesBondCar的一个实例,修改了一些状态数据,并想将间谍汽车(JamesBondCar)持久化到一个*.dat文件中。第一个任务是建立*.dat文件本身。这...

c# – AssemblyInformationalVersion属性行为改变:故意还是错误?【代码】

在使用VS2013构建的C#项目中,我可以将它放在AssemblyInfo.cs文件中:[assembly: AssemblyInformationalVersion("7.1.0.0 Private (Debug build)")]当我对另一个项目中的可执行文件使用FileVersionInfo.GetVersionInfo .NET API时,我发现这些值已报告: >产品版本:7.1.0.0 Private(Debug build)> ProductMajorPart:7> ProductMinorPart:1 当我在使用VS2015构建的C#项目中使用相同的属性和字符串值时,ProductMajorPart和ProductMi...

C# System.FormatException:“字符串的末尾有其他无法分析的字符。”

C#,某方法中,要把一个字符串转整数,但是报错: System.FormatException:“字符串的末尾有其他无法分析的字符。” Convert.ToInt32(str.Trim(), 2); 根据提示,看看字符串的末尾有没有什么奇怪的符号,比如空格、回车等,实际输出发现没有,前面代码逻辑中也不可能出现这些字符。 网上这个问题讨论的内容也很少。 探索一番,找到了原因。输出字符串看看:转换str:01111131 其实,这个错误提示带有一定的误导性。仔细看 Convert....

DATAFORMATSTRING - 相关标签
错误 - 相关标签