C# 中的初始化与实例化

csharpprogrammingserver side programming更新于 2025/7/12 20:07:17

初始化

在声明变量时为其赋值,这称为初始化。

以下是示例 −

int val = 50;

对于数组初始化,可能需要使用 new 关键字,而初始化变量则不需要。

实例化

在 C# 中使用 new 关键字为类创建新对象,这称为实例化。

在 C# 中使用 new 运算符实例化类。

以下示例展示了使用 new 关键字创建的两个 Student 类对象 −

Student s1 = new Student();
Student s2 = new Student();

相关文章