草庐IT

basic_string_view

全部标签

c# - 是否有 string.Join(string, string[]) 的 LINQ 等价物

这个问题已经存在:WhatistheLINQwaytoimplode/joinastringarray?[duplicate]关闭9年前。有什么方法可以使用LINQ将对象集合转换为单个新对象吗?我想在另一个LINQtoSQL表达式中使用它。

C# 使用 String.IsNullOrEmpty 切换

是否可以在C#中设置一个开关来检查值是否为null或空而不是“”而是String.Empty?我知道我可以做到:switch(text){casenull:case"":break;}有没有更好的东西,因为我不想有一大堆IF语句?我正在尝试替换:if(String.IsNullOrEmpty(text))blah;elseif(text="hi")blah 最佳答案 我建议如下:switch(text??String.Empty){case"":break;case"hi":break;}这就是你要找的吗?

c# - 未编译的局部 View 不继承自 ViewImports

我将View的一部分移动到局部View中。_ViewImports.cshtml@usingAsonCore.Helpers@usingAsonCore.Models@namespaceAsonCore.Pages@addTagHelper*,Microsoft.AspNetCore.Mvc.TagHelpers应用程序.cshtml@page@modelApplicationModel_ApplicationPartial.cshtml@modelApplicationModelFORNAVNETTERNAVN_Project.csprojnetcoreapp2.2InProcess

c# - IIS 不识别 View 模型注释

我有一个带有注释的基本MVCView模型,例如:[Required(ErrorMessage="YourNameRequired")][Display(Name="YourName")][DataType(DataType.Text)][MaxLength(120,ErrorMessage="Mustbeunder120characters")]publicStringYourName{get;set;}我有一个基于此View模型的强类型View。当我在本地运行应用程序时,以下代码生成“您的姓名”标签:@Html.LabelFor(model=>model.YourName)当应用程序

c# - 为什么我的 string.indexof(char) 更快?

不要问我是怎么到那儿的,但我一直在玩弄一些掩码、循环展开等。无论如何,出于兴趣,我在考虑如何实现一个indexof方法,长话短说,所有除了屏蔽等,这个天真的实现:publicstaticunsafeintIndexOf16(strings,intstartIndex,charc){if(startIndex=s.Length)thrownewArgumentOutOfRangeException("startIndex");fixed(char*cs=s){for(inti=startIndex;i比string.IndexOf(char)快。我写了一些简单的测试,它似乎与输出完全匹配

c# - 为什么 string.Normalize 不一致取决于上下文?

我有以下代码:stringinput="ç";stringnormalized=input.Normalize(NormalizationForm.FormD);char[]chars=normalized.ToCharArray();我在64位Windows7上使用VisualStudio2010、.net4构建此代码。我在两个上下文中的单元测试项目(平台:任何CPU)中运行它并检查chars的内容:VisualStudio单元测试:字符包含{231}。ReSharper:字符包含{231}。NCrunch:字符包含{99,807}。在msdndocumentation,我找不到任何

c# - string.IndexOf OrdinalIgnoreCase 与 CurrentCultureIgnoreCase 的性能

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Stringcomparisonindotnetframework4我注意到我机器上的一个UI应用程序存在性能问题,该应用程序正在执行大量字符串比较以过滤大型列表。我将问题追溯到在对string.IndexOf的调用中使用OrdinalIgnoreCase。以下基准测试是在没有附加调试器的情况下在Release中运行的,它是一个在VS2010、Windows7中构建的4.0项目,我在这台机器上安装了4.5beta,我不确定这是否会影响它。1.190secondsforOrdinalIgnoreCase0.17

C# 字典性能 : Default string Comparer's GetHashCode() allocates memory in violation of guidelines, 从而破坏性能?

有anestablishedguideline获取哈希码不应分配内存,因为这会通过调用垃圾收集器对哈希表查找产生负面影响。然而,这个确切的失败是我所看到的我使用System.Collections.Generic.Dictionary的应用程序的配置文件在一个非常紧凑的循环中,我在分析器结果中发现以下内容:[3.47%]TryGetValue(TKey,TValue&)(...字典)[3.47%]FindEntry(TKey)(...字典)[3.47%]GetHashCode(string)(System.CultureAwareComparer)[3.46%]GetHashCodeO

c# - 测试 ASP.NET MVC View 模型

我正在使用Nunit和Moq来测试我的asp.netmvc解决方案。这是测试传递给View的模型是否是正确对象/集合的好方法吗?[Test]publicvoidStart_Page_Should_Display_Posts(){varposts=newList{newPost{Id=1},newPost{Id=2}};varmock=newMock();mock.Setup(x=>x.FindAll()).Returns(posts.AsQueryable());varcontroller=newPostsController(mock.Object);varresult=contro

c# - OpenXML 中的 CellValues.InlineString 和 CellValues.String 有什么区别?

我正在尝试编写一些代码来生成Excel电子表格,但我不确定CellValues.InlineString和CellValues.String在细胞。我应该用这个吗:privatevoidUpdateCellTextValue(Cellcell,stringcellValue){InlineStringinlineString=newInlineString();TextcellValueText=newText{Text=cellValue};inlineString.AppendChild(cellValueText);cell.DataType=CellValues.InlineS