C # का const
जावा के समान सटीक है final
, सिवाय इसके कि यह हमेशा होता है static
। मेरी राय में, एक const
चर के लिए वास्तव में गैर होना आवश्यक नहीं है static
, लेकिन यदि आपको एक const
चर को गैर- तक पहुँच की आवश्यकता है static
, तो आप यह कर सकते हैं:
class MyClass
{
private const int myLowercase_Private_Const_Int = 0;
public const int MyUppercase_Public_Const_Int = 0;
/*
You can have the `private const int` lowercase
and the `public int` Uppercase:
*/
public int MyLowercase_Private_Const_Int
{
get
{
return MyClass.myLowercase_Private_Const_Int;
}
}
/*
Or you can have the `public const int` uppercase
and the `public int` slighly altered
(i.e. an underscore preceding the name):
*/
public int _MyUppercase_Public_Const_Int
{
get
{
return MyClass.MyUppercase_Public_Const_Int;
}
}
/*
Or you can have the `public const int` uppercase
and get the `public int` with a 'Get' method:
*/
public int Get_MyUppercase_Public_Const_Int()
{
return MyClass.MyUppercase_Public_Const_Int;
}
}
ठीक है, अब मुझे पता है कि यह सवाल 4 साल पहले पूछा गया था, लेकिन जब से मैंने लगभग 2 घंटे काम किया, जिसमें सभी तरह के जवाब देने और कोड स्वरूपण के सभी तरीकों की कोशिश करना शामिल था, इस जवाब में, मैं अभी भी इसे पोस्ट कर रहा हूं। :)
लेकिन, रिकॉर्ड के लिए, मैं अभी भी थोड़े मूर्खतापूर्ण महसूस करता हूं।