覆盖和重载.net中的构造方法和析构方法是否 [英] Override and Overloading the Constructors and Destructors in .net yes are no

查看:40
本文介绍了覆盖和重载.net中的构造方法和析构方法是否的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi ..

我想要C#.net中的小混乱,构造函数和析构函数可以重写或不能重写,并且重载也请不要告诉我,并请给我一些解决方案的小示例,...............


谢谢.............

解决方案

可以像其他方法重载一样,通过改变参数签名来实现构造函数的重载. br/>
C#中的构造函数简介 [有关.Net中析构函数的信息 [ ^ ];您不能覆盖或重载析构函数(但是您可以在将被调用的任何类中指定一个,所以它有点像〜Object的覆盖).

构造函数可以像任何方法一样重载,但是覆盖它们与特定的new ...()调用相关联,并且放置在该类中的类指定应调用其构造函数,因此覆盖它们是没有意义的.


此处开始 [ 解决方案

Overloading of constructors can be done by varying parameter signature just like any other method overloading.

An Intro to Constructors in C#[^]

However overriding of constructors is not supported ib C# or .NET since the purpose of the constructor is to initialize the members of class it is contained in, there is no need to override it to overide the functionality of the constructor in the base class.


Information about destructors in .Net[^]; you can''t override or overload a destructor (but you can specify one in any class which will be called, so it''s kind of an override of ~Object).

Constructors can be overloaded like any method, but it doesn''t make sense to override them as they''re associated with a particular new ...() invocation and the class you put there specifies whose constructor should be called.


Start here[^].


这篇关于覆盖和重载.net中的构造方法和析构方法是否的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆