निम्नलिखित वर्ग पर विचार करें:कक्षा के स्थिर सदस्यों पर अजीब व्यवहार - यह कैसे संभव है?
public class MyClass
{
public static string[] SomeAmazingConsts = { Const1 };
public static string Const1 = "Constant 1";
public static string Const2 = "Constant 2";
}
अब उपयोग की जाँच:
class Program
{
static void Main(string[] args)
{
string[] s = MyClass.SomeAmazingConsts;
//s[0] == null
}
}
समस्या यह है कि एस [0] == रिक्त है! यह बिल्ली कैसे होता है? अब, MyClass के स्थिर चर को निम्नानुसार पुन: क्रमबद्ध करें:
public class MyClass
{
public static string Const1 = "Constant 1";
public static string Const2 = "Constant 2";
public static string[] SomeAmazingConsts = { Const1 };
}
चीजें ठीक से काम करना शुरू कर देती हैं। कोई भी इस पर कुछ प्रकाश डाल सकता है?
आप सरणी के लिए एक अशक्त संदर्भ बताए जाते हैं, यह जादुई साथ फिर से असाइन नहीं मिल सकता है संशोधित मान – jedgard