草庐IT

convert_it

全部标签

c# - 使用 Moq.It.IsAny 测试以某物开头的字符串

是否可以使用Moq来表示一个方法接受以“ABC”开头的字符串。举个例子:logger.Verify(x=>x.WriteData(Moq.It.IsAny().StartsWith("ABC")),Times.Exactly(3));那不会编译,但希望它能说明我的观点 最佳答案 尝试:logger.Verify(x=>x.WriteData(Moq.It.Is(str=>str.StartsWith("ABC"))),Times.Exactly(3));你可以看到It.Is的另一个例子://matchingFunc,lazyeval

c# - "This BackgroundWorker states that it doesn' t 报告进度。”- 为什么?

我是这个后台worker的新手我已经阅读了一些关于如何创建一个的文章这是它产生的privatevoidbackgroundWorker1_DoWork(objectsender,DoWorkEventArgse){Bitmapimgbox=newBitmap(pictureBox.Image);intimgHeight=imgbox.Height;intimgWidth=imgbox.Width;intcounter=1;MinMaxWidth=imgWidth-50;MaxWidth=imgWidth;try{Colorc;//Colorc2;for(inti=0;i但是当我开始Do

c# - DateTime.Parse 和 Convert.ToDateTime 之间有什么区别?

有什么区别吗Convert.ToDateTime和DateTime.Parse哪个更快或哪个更安全? 最佳答案 根据answeronanotherforumfromJonSkeet...Convert.ToDateTimeusesDateTime.Parseinternally,withthecurrentculture-unlessyoupassitnull,inwhichcaseitreturnsDateTime.MinValue.如果您不确定字符串是否是有效的DateTime,则两者都不使用,而是使用DateTime.TryP

c# - TypeConverter 与 Convert 与 TargetType.Parse

据我所知,.NET中至少有3种数据类型转换的方法:使用System.ComponentModel.TypeConvertervarconv=System.ComponentModel.TypeDescriptor.GetConverter(typeof(int));vari1=(int)conv.ConvertFrom("123");使用System.Convert.ChangeType():vari2=(int)Convert.ChangeType("123",typeof(int));使用Parse/TryParse目标类型的方法:vari3=int.Parse("123");//

c# - VS 2017 : The security debugging option is set but it requires the Visual Studio hosting process which is unavailable

我的解决方案(包含十几个项目)在VisualStudio2013中完美运行。在VisualStudio2017中,我可以打开解决方案并进行编译。但如果我开始调试,我会系统地收到此错误消息:ThesecuritydebuggingoptionissetbutitrequirestheVisualStudiohostingprocesswhichisunavailableinthisdebuggingconfiguration.Thesecuritydebuggingoptionwillbedisabled.Thisoptionmaybere-enabledintheSecuritypro

c# - 有没有尝试 Convert.ToInt32 ...避免异常

我想知道是否有一种“安全”的方法可以将对象转换为int,从而避免异常。我正在寻找类似publicstaticboolTryToInt32(objectvalue,outintresult);我知道我可以做这样的事情:publicstaticboolTryToInt32(objectvalue,outintresult){try{result=Convert.ToInt32(value);returntrue;}catch{result=0;returnfalse;}}但我宁愿避免异常,因为它们会减慢进程。我认为这样更优雅,但仍然“廉价”:publicstaticboolTryToInt

c# - 错误 : Reference to type claims it is defined, 但找不到

我有一个包含3个项目的解决方案:ParsersBase,它定义了一个接口(interface)IParseRuleParsersLibrary,它引用了ParsersBase并定义了一个类HtmlImageUrlParseRule:IParseRuleParsersLibraryTest,它引用了ParsersBase和ParsersLibrary并定义了一个带有一些测试方法的测试类当我尝试构建它时,我收到警告:Referencetotype'AVSoft.ParsersBase.IParseRule'claimsitisdefinedin'c:\Users\Tim\Dropbox\p

c# - 获取 "Tuple element name is inferred. Please use language version 7.1 or greater to access an element by its inferred name."

直到今天,在我们将VisualStudio2017更新到最新的15.3之后,我们的UWP应用程序中的以下代码一直运行良好。privatevoidTest(){vargroups=newListitems)>();varitems=newList{("a",true),("b",false),("c",false)};vargroup=(Guid.NewGuid(),items);groups.Add(group);}在输出窗口中没有错误信息但是这个Tupleelementname'items'isinferred.Pleaseuselanguageversion7.1orgreater

c# - 什么是最快的 : (int), Convert.ToInt32(x) 或 Int32.Parse(x)?

以下哪段代码是转换某些对象x的最快/最佳实践?intmyInt=(int)x;或intmyInt=Convert.ToInt32(x);或intmyInt=Int32.Parse(x);或者在字符串's'的情况下intmyInt;Int32.TryParse(s,outmyInt);我很好奇对于在Convert中具有方法的数据类型,哪种执行速度最快,而不仅仅是整数。我只是以int为例。编辑:这个案例源于从数据表中获取信息。(int)仍然是最快的吗?根据一些测试,当对象x=123123123时,int执行速度最快,正如许多人所说。当x是字符串时,Parse运行最快(注意:cast会抛出异

c# - 无法生成临时类(结果=1)。错误 CS0030 : Cannot convert type 'Type[]' to 'Type' ?

我在使用xsd.exe工具从我的xsd文件创建类后收到此错误。所以我在网上搜索并找到了解决方案。这是链接:http://satov.blogspot.com/2006/12/xsdexe-generated-classes-causing.html问题是这会使代码运行,但反序列化的数据似乎已损坏。我按照网站的建议做了,最后第二个数组维度总是空的(见网站的评论,有人也有这个问题)。问题是,我现在该如何解决这个问题?是否有其他工具可以创建xsd文件?我尝试了Xsd2Code,但没有成功。谢谢:-) 最佳答案 您需要更改序列化类中的成员变