草庐IT

enum和set

全部标签

c# - 为什么我需要使用 get 和 set?

我有一段代码:publicclassMyClass{privatestring_myProperty;publicstringMyProperty{get{return_myProperty;}set{_myProperty=value;}}}这里有什么意义?我可以将_myProperty字符串声明为公共(public)字符串,我的任何类对象都可以直接访问它们并获取或设置值。相反,我们将_myProperty设为私有(private),并使用类对象使用get和set来访问它们。在任何一种情况下,类对象都能够访问它们并且结果总是相同的。那么为什么要使用这种方法呢?这仅仅是因为我可以在se

c# - DDD : Enum like entities

我有以下数据库模型:**Persontable**ID|Name|StateId------------------------------1Joe12Peter13John2**Statetable**ID|Desc------------------------------1Working2Vacation领域模型将是(简化的):publicclassPerson{publicintId{get;}publicstringName{get;set;}publicStateState{get;set;}}publicclassState{privateintid;publicstri

c# - EF 查询 Oracle 抛出 "ORA-12704: character set mismatch"

我试图在Oracle的EF中组合几列,然后像这样对这些列执行.Contains():publicIEnumerableSearchUsers(stringsearch){search=search.ToLower();return_securityUow.Users.Where(u=>(u.FirstName.ToLower()+""+u.LastName.ToLower()+"("+u.NetId.ToLower()+")").Contains(search)).OrderBy(u=>u.LastName).ThenBy(u=>u.FirstName).AsEnumerable();

c# - Enum.ToString() 已弃用?

当我在VisualStudio中的Enum类型上键入.ToString()时,Intellisense显示通过ToString()(虽然它构建并工作正常)。这似乎表明Enum.ToString()在某种程度上已被弃用。这是真的?如果是,为什么? 最佳答案 采用IFormatProvider的Enum.ToString重载,ToString(IFormatProvider)和ToString(String,IFormatProvider),都已过时,因为无论如何都没有使用IFormatProvider。其他重载,ToString()和

c# - 公共(public)静态字符串 MyFunc() 上的 "Expected class, delegate, enum, interface or struct"错误。什么 's an alternative to "字符串”?

当我尝试使用以下静态函数时出现错误。错误:Expectedclass,delegate,enum,interface,orstruct函数(和类):namespaceMyNamespace{publicclassMyClass{//SomeotherstaticmethodsthatuseClasses,delegates,enums,interfaces,orstructspublicstaticstringMyFunc(stringmyVar){stringmyText=myVar;//DosomestuffwithmyTextandmyVarreturnmyText;}}}这导致

c# - DataAnnotations 命名空间中的 Enum 值是否有开箱即用的验证器?

C#枚举值不仅限于其定义中列出的值,还可以存储其基类型的任何值。如果未定义基类型,则使用Int32或仅使用int。我正在开发一个WCF服务,它需要确信某些枚举已经分配了一个值,而不是所有枚举的默认值0。我从一个单元测试开始,以确定[Required]会在这里做正确的工作。usingSystem.ComponentModel.DataAnnotations;usingXunit;publicenumMyEnum{//Ialwaysstartfrom1inordertodistinctfirstvaluefromthedefaultvalueFirst=1,Second,}publiccl

c# - "Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to OFF"带复合键

我们最近向我们的数据库添加了一个新的“级别”——在整个数据库中的表中现有ID身份字段的上方/之前添加了一个键“Company_ID”。例如,如果一个表有ID然后是字段,它现在有Company_ID,然后是ID,然后是字段。这个想法是,这允许ID为提供给功能的每个不同的Company_ID值自动递增(Company_ID1可以有ID1、2、3等;Company_ID2可以有ID1、2、3等)。自增字段保持为ID。一个示例表是:[dbo].[Project]([Company_ID][int]NOTNULL,[ID][int]IDENTITY(1,1)NOTNULL,[DescShort]

c# - 隐式类型数组 : why we can't set array size explicitly?

C#语言规范(7.6.10.4)说,数组创建表达式有树种:newnon-array-type[expression-list]rank-specifiersoptarray-initializeroptnewarray-typearray-initializernewrank-specifierarray-initializer第三个用于隐式类型数组:varfoo=new[]{1,2,3};问题:在隐式类型数组的情况下,是否有任何重要的理由禁止显式设置数组大小?与这种语法相比,它看起来像是不对称行为:varfoo=newint[3]{1,2,3};更新。稍微澄清一下。我可以看到,显式设

c# - Visual Studio 显示 ReSharper 的 'Configure settings to improve performance' 通知

我正在使用VisualStudioProfessional201715.5.2和Resharper2017.3.1。每次我打开VS,它都会抛出通知Configuresettingstoimproveperformance.我尝试忽略此消息,但每次启动新实例时都会抛出它。当这不起作用时,我单击了消息,它带我进入了Resharper性能指南选项。我尝试更改正在使用的SourceControl插件的设置。。我将其值更改为忽略,但消息仍然存在。2Questions1.WhatisslowinginResharperforwhichVSthrowsthiserror?2.Whyisthisnot

c# - ManualResetEventSlim : Calling . Set() 后跟 .Reset() 不会释放 *任何* 等待线程

ManualResetEventSlim:调用.Set()后立即调用.Reset()不会释放任何等待线程(注意:ManualResetEvent也会发生这种情况,而不仅仅是ManualResetEventSlim。)我在发布和Debug模式下都尝试了下面的代码。我在四核处理器上运行的Windows764位上使用.Net4作为32位版本运行它。我从VisualStudio2012编译它(因此安装了.Net4.5)。在我的系统上运行它时的输出是:Waitingfor20threadstostartThread1started.Thread2started.Thread3started.Th