草庐IT

IS_STRING

全部标签

C# 添加 string + null 不会抛出错误?

作为一名程序员,我本以为这会引发异常。是否有将null视为“”的原因?strings="hello";stringt=null;Console.WriteLine(s+t);输出:hello只是为了强调我的问题,您知道为什么决定将null转换为String.Empty吗?我原以为会添加一些字符串,但后面出现了一个问题,它没有正确检索它并且返回了null。问题没有引起注意!这是我认为它不好的原因的伪代码(以及为什么我很震惊地发现没有错误):您可以假设我重载了ToString以提供此人的姓名或有关他们的详细信息。Personp=PersonDatabase.GetForName("Jimm

c# - 运算符 '==' 不能应用于 linq to entity 中类型为 'System.Guid' 和 'string' 的操作数

我在linqtoentityframework代码下方收到此错误“运算符‘==’无法应用于‘System.Guid’和‘string’类型的操作数”。在下面的代码中,CustomerId是Guid,customerProfileId是字符串。varaccountQuery=fromCinCustomerModel.CustomerProfilewhereC.CustomerId==customerProfileId//ErrorhereselectC; 最佳答案 您不能直接将Guid与字符串进行比较。将字符串转换为Guid或将Gui

C# 用 LINQ 用相同的模式替换 List<string> 的所有元素

我有一个包含数千个字符串的C#列表:"2324343""6572332""45122"...我想用括号把它们全部替换掉​​,这样它们看起来像"(2324343)""(6572332)""(45122)"...我知道如何编写for循环并执行此操作,但我想知道是否有一种方法可以更好地使用LINQ和LAMBDA表达式来执行此操作。我也愿意接受其他建议。非常感谢! 最佳答案 varresultList=list.Select(x=>string.Format("({0})",x)).ToList();

c# - 检查 int、string、double 等任何类型的 null 或 empty 的通用方法

我正在尝试让它工作,但不知何故它超出了我的控制范围......我希望能够检查null或empty到我分配的任何类型。例如:inti=0;stringmystring="";varreult=CheckNullOrEmpty(10)//passingintvarresult1=CheckNullOrEmpty(mystring)//passingstringpublicboolCheckNullOrEmpty(Tvalue){//checkfornulloremptyforstrings//checkfornulli.e.0forint}有人可以帮我解决这个问题吗?我想了解泛型如何适用于

c# - Resharper 中的警告 "Return value of pure method is not used"

我有一个快速的问题,关于我正在工作的c#项目中从VisualStudio中的Resharper收到的警告。警告是:"ReturnValueofpuremethodisnotused"发生这种情况的方法如下:privatestaticboolFilePathHasInvalidChars(stringuserInputPath){try{//thisiswherethewarningoccurs:Path.GetFullPath(userInputPath);}catch(Exceptione){Log.Error(String.Format("TheProgramfailedtorun

c# - 多线程,Task.Run 错误 'The call is ambiguous between the following methods or properties'

当我尝试构建项目时,显示以下错误消息。Thecallisambiguousbetweenthefollowingmethodsorproperties:'System.Threading.Tasks.Task.Run(System.Action)'and'System.Threading.Tasks.Task.Run(System.Func)'我该如何解决这个问题?publicstaticclassMaintananceManager{privatestaticThreadSafeSocialMediaListPostList=newThreadSafeSocialMediaList(

c# - 将 string[] 转换为 Int[] 而不丢失前导零

输入:stringparam="1100,1110,0110,0001";输出:int[]matrix=new[]{1,1,0,0,1,1,1,0,0,1,1,0,0,0,0,1};我做了什么?首先,我将字符串拆分为字符串[]。string[]resultantArray=param.Split(',');创建了一个方法,我在其中传递了我的字符串[]。varintArray=toIntArray(resultantArray);staticprivateint[]toIntArray(string[]strArray){int[]intArray=newint[strArray.Len

C# 应用程序设置 : Is there a easy way to put a collection into <appSetting>

我试过了和System.Configuration.ConfigurationManager.AppSettings.GetValues("List");但我只得到最后一个成员。我怎样才能轻松解决这个问题? 最佳答案 我处理过类似的问题,我是用这段代码解决的。希望这对您的问题有所帮助。在这种情况下,列表(类似于我的URLSection)将在web.config中有一个完整的配置部分,然后您可以从该部分获取所有值。我为此创建了三个类:ConfigElement、ConfigElementCollection、WebConfigSect

c# - 一行 LINQ 将 string[] 展平为字符串?

我想出了下面的foreach,但我希望这可以在一行中完成。也许是linq?任何想法将不胜感激。foreach(stringitemindecoder.AllKeys){message+=String.Format("{0}:{1};",item,decoder[item]);} 最佳答案 varmessage=string.Join(";",decoder.AllKeys.Select(x=>string.Format("{0}:{1}",x,decoder[item])).ToArray());

c# - 在 C# winform 中,我得到了 : "only truetype fonts are supported. This is not a TrueType Font"

我有C#winform,我安装了几个ttf字体,但是当我将文本框字体设置为我下载的任何字体时,我得到这个错误即使我100%确定我安装的字体是ttf..为什么?以及如何解决这个问题? 最佳答案 当您在VisualStudio运行时安装新字体时会发生这种情况。关闭VisualStudio,然后重新打开它。问题就解决了。 关于c#-在C#winform中,我得到了:"onlytruetypefontsaresupported.ThisisnotaTrueTypeFont",我们在StackOv