草庐IT

abstract-class

全部标签

c# - .NET 属性生成 "must declare a body because it is not marked abstract or extern"编译错误

我有一个.NET3.5(目标框架)网络应用程序。我有一些看起来像这样的代码:publicstringLogPath{get;privateset;}publicstringErrorMsg{get;privateset;}它给我这些行的编译错误:"mustdeclareabodybecauseitisnotmarkedabstractorextern."有什么想法吗?我的理解是这种风格的属性在.NET3.0中是有效的。谢谢!原来问题出在我的.sln文件本身。尽管我在构建选项中更改了目标版本,但在.sln文件中,我发现了这一点:TargetFramework="3.0"将其更改为“3.5

c# - 通过反射仅获取当前类(class)成员

假设这段代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Reflection;namespaceTestFunctionality{classProgram{staticvoidMain(string[]args){//System.Reflection.Assembly.GetExecutingAssembly().LocationAssemblyassembly=Assembly.LoadF

C#/N 休眠 : Association references unmapped class

几个小时以来,我一直在努力解决这个NHibernate问题。我在网络和NHibernate文档上进行了广泛的研究,但我无法理解这个问题。我对NHibernate比较陌生,但很喜欢它。不过,在那种情况下,它让我发疯。我正在为网站编写一个小型“投票”模块。我有几个类(Poll、PollVote和PollAnswer)。主要的Poll是导致问题的原因。这就是类的样子:publicclassPoll{publicvirtualintId{get;set;}publicvirtualSiteSite{get;set;}publicvirtualstringQuestion{get;set;}pu

c# - cs0030 :Unable to generate a temporary class

我有一个Web服务,当我尝试生成它的对象时出现以下错误。"Unabletogenerateatemporaryclass(result=1).errorCS0030:Cannotconverttype'ShortSell.ShortSellRQOriginDestinationInformationFlightSegment[]'to'ShortSell.ShortSellRQOriginDestinationInformationFlightSegment'errorCS0030:Cannotconverttype'ShortSell.ShortSellRSOriginDestina

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# - OOPS 概念 : What is the difference in passing object reference to interface and creating class object in C#?

我有一个类CustomerNew和一个接口(interface)ICustomer:publicclassCustomerNew:ICustomer{publicvoidA(){MessageBox.Show("Classmethod");}voidICustomer.A(){MessageBox.Show("Interfacemethod");}publicvoidB(){MessageBox.Show("ClassMethod");}}publicinterfaceICustomer{voidA();}我对这两行代码很困惑。ICustomerobjnew=newCustomerNe

c# - 在通用抽象类中实现强制转换运算符

我试图偷懒并在抽象基类中而不是在每个派生的具体类中实现转换运算符。我已经设法施放了一种方式,但无法施放另一种方式。我认为这可能是不可能的,但想在放弃之前选择集体SO的想法:publicinterfaceIValueType{TValue{get;set;}}publicabstractclassValueType:IValueType{publicabstractTValue{get;set;}publicstaticexplicitoperatorT(ValueTypevt){if(vt==null)returndefault(T);returnvt.Value;}publicsta

c# - 在 C# 中重构抽象类

抱歉,如果这听起来很简单,但我正在寻找一些帮助来改进我的代码:)所以我目前有以下实现(我也写过):publicinterfaceIOptimizer{voidOptimize();stringOptimizerName{get;}}publicabstractAbstractOptimizer:IOptimizer{publicvoidOptimize(){//Generalimplementationherewithfewcallstoabstractmethods}}publicabstractAbstractPriorityOptimizer:AbstractOptimizer{

c# - ASP.net Web API : change class name when serializing

我有一个产品的数据传输对象类publicclassProductDTO{publicGuidId{get;set;}publicstringName{get;set;}//Otherproperties}当Asp.net序列化JSON(使用JSON.NET)或XML中的对象时,它会生成ProductDTO对象。但是,我想在序列化期间更改名称,从ProductDTO到Product,使用某种属性:[Name("Product")]publicclassProductDTO{[Name("ProductId")]publicGuidId{get;set;}publicstringName{

C# 设计 : Why is new/override required on abstract methods but not on virtual methods?

为什么抽象方法需要new/override而虚方法不​​需要?示例1:abstractclassShapesClass{abstractpublicintArea();//abstract!}classSquare:ShapesClass{intx,y;publicintArea()//Error:missing'override'or'new'{returnx*y;}}编译器会显示这个错误:要使当前成员覆盖该实现,请添加override关键字。否则添加新关键字示例2:classShapesClass{virtualpublicintArea(){return0;}//itisvirt