In C# all methods must be declared inside a class. However, if you declare a method or field as static, you can call the method or access the fields by using the name of the lass. No instance is required.
class RFClass
{
public static double converter(double inp1)
{
return inp1 * 3;
}
}
dedigin zaman, main fonksiyon icindeyken asagidaki komut calisiyor;
double d2 = RFClass.converter(423);
Creating a Shared Field in a class
-- Objenin icindeki variable a field denir
When defining a field, you can use the static keyword so the field becomes available to all methods in an object, hence becoming shared field.
Creating a static field with const Keyword
When you define a field with const keyword, it automatically becomes static - available to all methods or outside calls- but can not be changed since it's defined as a constant. You can only define int, double or string as a constant
Static Class
In order to use as a utility class, hold variables and call methods, you can also define a static class.
Ama sadece class'i static olarak define edip de field lari static olarak tanimlamazsak onlar otomatikman statik olmuyorlar.. Yani
public static class StaticClass1
{
public int dem = 0;
public double demd = 0.0412;
}
dedigimizde, dem veya demd disardan accessible static variable lar olarak islemiyor.
Thursday, July 11, 2013
Subscribe to:
Post Comments (Atom)
Categories
Blog Archive
-
▼
2013
(24)
-
▼
July
(14)
- Polymorphism nedir
- Static Fields in a class
- What is a constructor
- Defining and using a class and Constructor
- Memory Usage by Classes, Methods and Functions
- Encapsulation 3
- What is Encapsulation 2
- What is Encapsulation
- Reading and Writing to a File
- Exception Example
- Beginning Visual C# 2010
- Animated Elipse in C#
- Ref and Out in Visual C#
- How to download an image from a website using c#
-
▼
July
(14)
Popular Posts
Powered by Blogger.
0 comments:
Post a Comment