本文介绍了什么是“静态"的?班级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,有什么区别:

In C# what is the difference between:

public static class ClassName {}

并且:

public class ClassName {}

推荐答案

静态类无法实例化,并且只能包含静态成员.因此,对静态类的调用为:MyStaticClass.MyMethod(...)MyStaticClass.MyConstant.

A static class cannot be instantiated, and can contain only static members. Hence, the calls for a static class are as: MyStaticClass.MyMethod(...) or MyStaticClass.MyConstant.

可以实例化一个非静态类,并且可以包含非静态成员(实例构造函数,析构函数,索引器).非静态类的非静态成员只能通过对象调用:

A non static class can be instantiated and may contain non-static members (instance constructors, destructor, indexers). A non-static member of a non-static class is callable only through an object:

MyNonStaticClass x = new MyNonStaticClass(...);
x.MyNonStaticMethod(...);

这篇关于什么是“静态"的?班级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 02:08