什么是一个静态变量之间的C ++与C#的区别? [英] What is the difference between a static variable in C++ vs. C#?

查看:159
本文介绍了什么是一个静态变量之间的C ++与C#的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

做静态变量在C#中的相同或类似的功能,因为他们用C做++

Do static variables have the same or similar functionality in C# as they do in C++?

编辑:

使用C ++,你可以在许多不同的情况下使用静态变量 - 例如:1)全局变量,2)本地函数变量,3)班的成员 - 将会用C#类似最终用途的行为类似于C ++的

With C++ you can use static variables in many different contexts - such as: 1) Global variables, 2) Local function variables, 3) Class members - Would similar usages in C# behave similar to that of C++?

推荐答案

静态在C ++多重意义。

Static has multiple meanings in C++.

在C#中的静态变量基本上只有一个含义:变量范围限于一种类型。在C#,静态上​​的类型用于表示一个类型范围的变量。静态的一个方法是一种类型的范围的方法。静电也可以在一类用于表示整个类只包括静态方法,属性和字段

Static variables in C# basically only have a single meaning: variables scoped to a type. In C#, static on a type is used to denote a type-scoped variable. Static on a method is a type-scoped method. Static can also be used on a class to denote that the entire class is comprised only of static methods, properties, and fields.

有没有equivelent到内的静态变量。功能范围,或非类范围的静态值

There is no equivelent to static variables within a function scope, or non-class scoped static values.

编辑:

在效应初探您的编辑,C#基本上只使用静态的类成员。全局和局部静态函数变量在C#中不支持。此外,正如我上面提到的,你可以标记整个班级静,基本上只是让编译器检查,有在课堂上没有非静态成员。

In reponse to your edit, C# basically only uses static for class members. Globals and local static function variables are not supported in C#. In addition, as I mentioned above, you can flag an entire class "static", which basically just makes the compiler check that there are no non-static members in the class.

这篇关于什么是一个静态变量之间的C ++与C#的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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