C#asp.net中的构造函数 [英] Constructor in C# asp.net

查看:61
本文介绍了C#asp.net中的构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是构造函数?在哪个饱和度我们可以使用构造函数。请给我一些代码的实例。



我可以在没有构造函数的情况下完成需要构造函数的过程吗?



谢谢

pramod

What is constructor ? On which saturation we can use constructor. Please give me practical example with code.

Can i done the process without constructor where require constructor?

Thanks
pramod

推荐答案

看到这个,例如



< a href =http://www.c-sharpcorner.com/UploadFile/0c1bb2/constructors-and-its-types-in-C-Sharp/> http://www.c-sharpcorner.com/UploadFile/ 0c1bb2 / constructors-and-its-types-in-C-Sharp / [ ^ ]
see this, with example

http://www.c-sharpcorner.com/UploadFile/0c1bb2/constructors-and-its-types-in-C-Sharp/[^]


构造函数使程序员能够设置默认值,限制实例化和写入灵活且易于阅读的代码。

您可以在MSDN上找到非常干净和深入研究构造函数。

使用构造函数

构造函数(C#编程指南)
Constructors enable the programmer to set default values, limit instantiation, and write code that is flexible and easy to read.
You can find very clean and deeply study of Constructors on MSDN.
Using Constructors
Constructors (C# Programming Guide)


类中的构造函数是一个特殊类型,与声明类同名。

它准备使用新对象。

它与方法的不同之处在于它没有明确的返回类型。

使用重载构造函数,因为可以有更多一个类的构造函数。

构造函数在一个名为heap的特殊内存结构中为引用类型创建对象。

值类型(如int,double等)是在一个名为stack的顺序结构中创建的。

构造函数不能同步抽象或静态。

示例

A constructor in a class is a special type have the same name as the declaring class.
It prepares the new object for use.
It differs from a method in that it has no explicit return type.
Using overloading the constructor in that there can be more than one constructor for a class.
Constructor creates objects in a special memory structure called heap for reference types.
Value types (such as int, double etc.), are created in a sequential structure called stack.
Constructors cannot be synchronized abstract or static.
Example
public class CC
{
    private int a;
    private string b;

    // Constructor
    public CC() : this(42, "string")
    {
    }

    // Overloading a constructor
    public CC(int a, string b)
    {
        this.a = a;
        this.b = b;
    }
}


这篇关于C#asp.net中的构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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