草庐IT

new_class

全部标签

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# - XMLReader.Create() 和 new XMLTextReader() 之间的区别

我想了解XMLReader.Create和newXMLTextReader()读取XML的区别。我为什么要选择一个而不是另一个?有性能差异吗?我知道XMLReader是XMLTextReader的抽象类型,至少我之前是这样读的,但我看到有人建议使用XMLReader.Create()方法而不是新的XMLReader()实例。提前致谢...真诚的。 最佳答案 XmlReader.Create允许您指定XmlReaderSettings,XmlTextReader构造函数重载均不执行此操作。

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# new in 方法声明

publicnewintAdjustedBaseValue这里的new是什么意思或作用? 最佳答案 这意味着您正在隐藏int值。它在基类中声明,而您在派生类中重新声明它,有效地隐藏了基类版本。参见文档here获取更多信息。引用示例here 关于C#newin方法声明,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4764382/

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# - 在 C# 中使用 'new' 修饰符

我读到new修饰符隐藏了基类方法。usingSystem;classA{publicvoidY(){Console.WriteLine("A.Y");}}classB:A{publicnewvoidY(){//ThismethodHIDESA.Y.//ItisonlycalledthroughtheBtypereference.Console.WriteLine("B.Y");}}classProgram{staticvoidMain(){Aref1=newA();//DifferentnewAref2=newB();//PolymorpishmBref3=newB();ref1.Y(

c# - 哪个是首选 : new Nullable<int> or (int? )null?

在这样的表达式中首选哪种方式:int?Id{get{inti;returnInt32.TryParse(Request["id"],outi)?i:(int?)null;}}在null上转换更好吗?或者创建一个newNullable? 最佳答案 最好的是default(int?),因为它总是按预期工作(引用类型、值类型,甚至在泛型中)。 关于c#-哪个是首选:newNullableor(int?)null?,我们在StackOverflow上找到一个类似的问题:

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# - 何时使用 new 而不是重写 C#

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:C#keywordusagevirtual+overridevs.newDifferencebetweennewandoverride?所以我一直在做一个项目,并决定阅读一些有关C#中new和override关键字之间的区别的文章。据我所知,似乎使用new关键字功能是在代码中制造错误的好方法。除此之外,我真的看不出什么时候使用它才真正有意义。更多的是出于好奇,是否有任何模式可以让new关键字成为正确的方式?