静态变量优势 [英] static variable advantage

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

问题描述

我刚发送完代码后就发送了,

静态变量的优点是什么.


我们可以调用而不是仅创建对象或任何其他对象?


问候
James

i just sending after i was done the a code ,

what is advantage of static variable.


we can call instead of creating the object only,or anyother ?


regards
James

推荐答案

通常,我们不调用变量.但是,粗略地说,是的,实际上,我们可以访问(公共)静态变量而无需创建其类的实例.
静态成员应包含类属性,即类的所有实例共享的数据(如果没有创建对象,则所有都是).
Usually we don''t call a variable. However, roughly speaking, yes, actually we can access a (public) static variable without creating an instance of its class.
static members should contain class attributes, that is data shared by all the instances of the class (none is all when no object is created).


CPalini的回答是,C#定义了七类变量,其中包括静态变量.
在这里看看:
变量类别(C#) [静态变量(C#) [静态(C#参考) [
In addition of CPalini''s answer, C# defines seven categories of variables, among other things, static variables.
Have a look here:
Variable categories (C#)[^]
Static variables (C#)[^]

But i think, you want to know about static modifier (keyword). If yes, see here:
static (C# Reference)[^]

Use the static modifier to declare a static member, which belongs to the type itself rather than to a specific object. The static modifier can be used with classes, fields, methods, properties, operators, events, and constructors, but it cannot be used with indexers, destructors, or types other than classes.


静态变量还可以提高性能,因为它们将存储存储到一个单独的堆中,该堆与Garbage Collector堆(称为高频堆")分开.请参考静态关键字已神秘化 [
Static variables are also improving performance as they are getting stores into a separate heap, a separate heap from Garbage Collector heap, which is referring as "high frequency heap". Refer Static Keyword Demystified[^].

Also variables can be defined without taking additional memory.

Static variables resolved good designing changeless like Singleton implementation.

Just Google it you will get lot more information about it.

Thanks
Rushi


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

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