C# - Static Members
来源:互联网 发布:keep软件使用步骤 编辑:程序博客网 时间:2024/05/17 08:00
A non-static class can contain static methods, fields, properties, or events. The static member is callable on a class even when no instance of the class has been created. The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created. Static methods and properties cannot access non-static fields and events in their containing type, and they cannot access an instance variable of any object unless it is explicitly passed in a method parameter.
It is more typical to declare a non-static class with some static members, than to declare an entire class as static.Two common uses of static fields are to keep a count of the number of objects that have been instantiated, or to store a value that must be shared among all instances.
Static methods can be overloaded but not overridden, because they belong to the class, and not to any instance of the class.
Although a field cannot be declared asstatic const, a const field is essentially static in its behavior. It belongs to the type, not to instances of the type. Therefore, const fields can be accessed by using the sameClassName.MemberName notation that is used for static fields. No object instance is required.
C# does not support static local variables (variables that are declared in method scope).
Static members are initialized before the static member is accessed for the first time and before the static constructor, if there is one, is called.
If your class contains static fields, provide a static constructor that initializes them when the class is loaded.
A call to a static method generates a call instruction in Microsoft intermediate language (MSIL), whereas a call to an instance method generates acallvirt instruction, which also checks for a null object references. However, most of the time the performance difference between the two is not significant.
- C# - Static Members
- Static Members:
- Design with static members
- C++ static Class Members
- static data members
- Static members of class
- 7.6 Static Class Members
- CPP-static members
- Effective C#之13: Initialize Static Class Members with Static Constructors
- Static Classes and Static Class Members
- The Essence of OOP using Java: Static Members
- Why are classes with static data members getting linker errors?
- STL源码剖析:class template中拥有static data members
- C++类的静态成员(static members in classes)
- How to: Explicitly Implement Interface Members (C# Programming Guide)
- C# static
- C# static
- C# Static
- QString和string类型相互转换
- Mahout推荐算法API详解
- STM32的USART注意
- 20141128-OrCAD16.6输出有链接有属性信息的PDF
- 将科学计数法转为非科学计数法并显示小数位数
- C# - Static Members
- Python实现支持JSON存储和解析的对象
- 初学makefile
- MySQL客户端2006(CR_SERVER_GONE_ERROR)错误测试和优化方法
- 雷神3开方算法解析,游戏运行速度提高四倍。
- android Notification(通知) 的使用
- drools的JavaDialect异常
- Android UI系统控件进阶(一)之列表控件ListView详解
- 多线程编程——线程的同步(六)