有什么非静态类在静态类的优势是什么? [英] What are the advantages of non-static class over static class?

查看:115
本文介绍了有什么非静态类在静态类的优势是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是是非静态类的优势静态类?

What are the advantages of non-static class over static class?

静态类不需要被实例化。所以我们可以直接用 ClassName.MemberName ,所以后来有什么用非静态类

static class need not be instanciated. so we can directly use ClassName.MemberName, so then whats the use of nonstatic class

推荐答案

一个静态类是基本相同的非静态类,但有一个区别:静态类不能被实例化。换句话说,你不能使用new关键字创建类类型的变量。因为没有实例变量,可以使用类名称本身访问静态类的成员

A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, you cannot use the new keyword to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself

一个静态类具有类本身只有一个实例,所以你不能创建一个静态类的多个实例。

A static class has only one instance of the class itself so you cannot create multiple instance of a static class.

看着你的问题,你不能同时设置两个不同的值下面的属性,如果类是静态的,因为会有类名只有一个在内存中的实例

looking at your question you cannot set two different values to the below property if the class is static because there will be only one instance of ClassName in memory

ClassName.MemberName

更在

http://msdn.microsoft.com/en-us/library/ 79b3xss3.aspx

这篇关于有什么非静态类在静态类的优势是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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