草庐IT

new_value

全部标签

c# - 可观察集合 : calling OnCollectionChanged with multiple new items

请注意,我正在尝试使用NotifyCollectionChangedAction.Add操作而不是.Reset。后者确实有效,但对于大型收藏来说效率不高。所以我将ObservableCollection子类化:publicclassSuspendableObservableCollection:ObservableCollection出于某种原因,这段代码:privateList_cachedItems;...publicvoidFlushCache(){if(_cachedItems.Count>0){foreach(varitemin_cachedItems)Items.Add(i

c# - Visual C# 2010 速成版 : Specify default access modifier for new classes?

每当我使用VisualStudio2010ExpressC#创建新类时,它都会创建没有访问修饰符的新类。10次中有9次我希望我的新类(class)公开。如何让VisualStudio默认使用“public”修饰符创建空类模板? 最佳答案 诀窍是创建一个名为Class的新项模板。然后,当您执行“添加”>“新建类”时,默认情况下将选择您的模板,而不是内置的类模板。(我不确定这种行为是否得到保证,但它可以在我的机器上运行(TM)。)创建模板:右键单击您的项目并选择“添加”>“类”。您可以接受默认名称(Class1)-这只是一个临时文件。修

c# - new() 的通用类型约束和抽象基类

这里我们有一个简单的类层次结构,并且将泛型与typeconstraint一起使用new()的publicabstractclassBase{}publicclassDerived:Base{}publicclassTestClass{privatevoidDoSomething(Targ)whereT:new(){}publicvoidTestMethod(){Derivedd1=newDerived();DoSomething(d1);//compilesBased2=newDerived();DoSomething(d2);//compileerror}}代码在指示的行编译失败,错

c# - ASP.NET 核心,Web API : No route matches the supplied values

请注意:这个问题是在2016年提出的。这个问题的最初答案是更新microsoftapiversiong包。最近几天,问题再次出现,但由于其他原因。原始问题:我在asp.netcore(webapi)中遇到了一些路由问题。我有这个Controller(简化版):[ApiVersion("1.0")][Route("api/v{version:apiVersion}/[Controller]")]publicclassDocumentController:Controller{[HttpGet("{guid}",Name="GetDocument")]publicIActionResult

c# - PredicateBuilder.New 与 PredicateBuilder.True

我正在使用PredicateBuilder在我的操作中创建一个搜索/过滤器部分。在这里:[HttpPost]publicActionResultTest(int?cty,stringinumber,int?page){varlstValues=db.TableName.Include(x=>x.Table1).Include(x=>x.Table2).Include(x=>x.Table3).ToList();varpredicate=PredicateBuilder.True();if(!string.IsNullOrWhiteSpace(inumber)){predicate=pr

c# - Newtonsoft.Json.JsonSerializationException(从“System.Data.SqlTypes.SqlDouble”上的 'Value' 获取值时出错)序列化 SqlGeography

我尝试在数据库SQLServer2012中使用Newtonsoft.Json版本“Newtonsoft.Json.10.0.3”将DataTable对象序列化为Json。该表有一个类型为“geography”的列,其中包含类型为SqlGeography的实例.用于生成json的代码:publicstringSerializeToJson(){varconnstring1="DataSource=server1;InitialCatalog=database1;user=xxx;password=yyy";varsql="SELECT*FROMtable_1";//table_1hasa

c# - 通用约束 : Can I test Equality of generic that can be a reference or value type?

我想要一个通用类,它可以接受引用类型或值类型,并且只执行基于相等性测试的操作。考虑以下几点:publicclassPropertywhereTProp:struct,IEquatable{publicTPropValue;publicvoidSetValue(ObservableObjectowner,TPropvalue){if(!Value.Equals(value))//cannotuse!=onstructconstrainedTProp{//...settheproperty}}}publicclassByRefPropertywhereTProp:class//Dontwa

c# - 如何通过反射判断字段是否有 'new'修饰符?

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:HowdoIdetectthe"new"modiferonafieldusingreflection?有如下声明publicclassB:A{publicnewstringName;}我如何确定该字段的FieldInfo实例是否具有"new"修饰符?

c# - 接口(interface)继承和new关键字

我要:publicinterfaceIBase{MyObjectProperty1{get;set;}}publicinterfaceIBaseSub:IBase{newTProperty1{get;set;}}publicclassMyClass:IBaseSub{publicYourObjectProperty1{get;set;}}但这不能编译。它给出了错误://ThisclassmustimplementtheinterfacememberIBase.Property1任何人都可以阐明这一点吗?我认为它应该工作..谢谢 最佳答案

c# - 为什么在没有 new() 泛型类型约束的情况下允许 Activator.CreateInstance<T>() ?

在下面显示的示例代码中,“CompileError”方法不会编译,因为它需要whereT:new()CreateWithNew()中所示的约束方法。然而,CreateWithActivator()方法在没有约束的情况下编译得很好。publicclassGenericTests{publicTCompileError()//compileerrorCS0304{returnnewT();}publicTCreateWithNew()whereT:new()//buildsok{returnnewT();}publicTCreateWithActivator()//buildsok{ret