草庐IT

publications

全部标签

c# - 内部类的公共(public)构造函数是什么意思

这个问题在这里已经有了答案:What'sthedifferencebetweenapublicconstructorinaninternalclassandaninternalconstructor?(5个答案)关闭9年前。我见过一些C#代码声明了一个带有internal修饰符和public构造函数的类:internalclassSomeClass{publicSomeClass(){}}如果整个类的可见性是内部的,因此它只能在定义的程序集中可见,那么拥有公共(public)构造函数有什么意义?此外,如果SomeClass是嵌套类,这是否有意义?

c# - Autofac - 确保 Controller 有一个无参数的公共(public)构造函数

我知道之前有人问过这个问题并回答过-我问这个问题的原因是(我认为)我尝试了所有建议的解决方案来解决这个问题,但仍然无法解决。我有一个ASP.NETWebAPI2.0项目。我安装了Autofac、Autofac.Mvc5和Autofac.WebApi2依赖项。当我尝试调用APIController时,出现以下错误:Anerroroccurredwhentryingtocreateacontrolleroftype'MyController'.Makesurethatthecontrollerhasaparameterlesspublicconstructor.在我的Global.asax

c# - 属性(property)(没有额外处理)与公共(public)领域

这个问题在这里已经有了答案:Whatisthedifferencebetweenafieldandaproperty?(33个答案)关闭3年前。每当有关于属性可信度的问题时,我发现大部分讨论都是围绕函数/方法与属性展开的。但我也想知道令人信服的原因,即直接使用具有关联私有(private)字段的属性与公共(public)字段本身,以防最常见的获取/设置行为没有其他处理,我的意思是这样publicstringCustomerName;对比privatestringcustomerName;publicstringCustomerName{get{returncustomerName;}s

c# - "public new virtual void Method()"是什么意思?

什么时候使用新的虚关键字修饰方法?什么是感情?比如定义一个接口(interface),然后添加一个类来继承这个接口(interface)。而是使用新的virtual来实现接口(interface)方法。interfaceIPrinter{voidPrint();}publicclassPrinterOne:IPrinter{publicvoidPrint(){Console.WriteLine("PrinterOne.");}}publicclassPrinterTwo:PrinterOne{publicnewvirtualvoidPrint(){Console.WriteLine("

c# - 公开课 - "is inaccessible due to its protection level. Only public types can be processed."

我正在做一个测试项目来了解对象的XML序列化,但我遇到了一个奇怪的运行时错误:namespaceSerializeTest{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){}privatevoidserializeConnection(Connconnection){XmlSerializerserializer=newXmlSerializer(typeof(Conn));TextWritertextWrit

c# - 如何在 C# 中找到对象的所有公共(public)字段?

我正在构造一个方法来接收ArrayList(可能充满对象),然后列出ArrayList中每个对象的所有字段(及其值)。目前我的代码如下:publicstaticvoidListArrayListMembers(ArrayListlist){foreach(Objectobjinlist){Typetype=obj.GetType();stringfield=type.GetFields().ToString();Console.WriteLine(field);}}当然,我理解这段代码的直接问题:如果它有效,它只会为ArrayList中的每个对象打印一个字段。我稍后会解决这个问题-现在

c# 公共(public)嵌套类还是更好的选择?

我有一个控制电路,它有多个设置,并且可以连接任意数量的传感器(每个传感器都有自己的一组设置)。这些传感器只能与控制电路一起使用。我想像这样使用嵌套类:publicclassControlCircuitLib{//Fields.privateSettingscontrollerSettings;privateListattachedSensors;//Properties.publicSettingsControllerSettings{get{returnthis.controllerSettings;}}publicListAttachedSensors{get{returnthis

c# - 如何获取基类的公共(public)静态方法?

我的基类有一个公共(public)静态方法,但是当我调用typeof(TDerived).GetMethods(BindingFlags.Public|BindingFlags.Static)时,我的方法没有返回。(TDerived当然以某种方式继承self的基类)。我在此查询的位置没有对我的基类的引用。我做错了什么? 最佳答案 使用BindingFlags.FlattenHierarchy标志:typeof(TDerived).GetMethods(BindingFlags.Public|BindingFlags.Static|B

c# - Autofac - 自动注册错误 : No constructors can be found with 'Public binding flags'

这是我的Global.asax.cspublicvoidRegisterContainersUsingAutofac(){//http://elegantcode.com/2009/01/07/ioc-libraries-compared///http://www.codeproject.com/Articles/25380/Dependency-Injection-with-Autofac//https://code.google.com/p/autofac///http://api.autofac.org/varbuilder=newContainerBuilder();build

c# - 抽象类中 'public'构造函数的相关性

抽象类中的“公共(public)”构造函数是否有任何相关性?我想不出任何可能的方法来使用它,在那种情况下它不应该被编译器视为错误(C#,不确定其他语言是否允许这样做)。示例代码:internalabstractclassVehicle{publicVehicle(){}}C#编译器允许编译此代码,但我无法从外部世界调用此构造函数。它只能从派生类中调用。所以它不应该只允许“protected”和“私有(private)”修饰符。请评论。 最佳答案 没有理由为抽象类使用公共(public)构造函数。我认为编译器没有提示的原因很简单,他们