2010-02-26 9 views

उत्तर

45

तकनीकी रूप से, global कोई कीवर्ड नहीं है: यह एक तथाकथित "प्रासंगिक कीवर्ड" है। इन्हें केवल सीमित कार्यक्रम संदर्भ में विशेष अर्थ है और उस संदर्भ के बाहर पहचानकर्ता के रूप में उपयोग किया जा सकता है।

global जब भी अस्पष्टता हो या जब कोई सदस्य छिपा हुआ हो, तब भी इस्तेमाल किया जा सकता है और इसका उपयोग किया जाना चाहिए। here से:

// See: no namespace here 
public static class System 
{ 
    public static void Main() 
    { 
     // "System" doesn't have a namespace, so this 
     // will refer to this class! 
     global::System.Console.WriteLine("Hello, world!"); 
    } 
} 
:

class TestApp 
{ 
    // Define a new class called 'System' to cause problems. 
    public class System { } 

    // Define a constant called 'Console' to cause more problems. 
    const int Console = 7; 
    const int number = 66; 

    static void Main() 
    { 
     // Error Accesses TestApp.Console 
     Console.WriteLine(number); 
     // Error either 
     System.Console.WriteLine(number); 
     // This, however, is fine 
     global::System.Console.WriteLine(number); 
    } 
} 

हालांकि, ध्यान दें कि global जब कोई नाम स्थान प्रकार के लिए निर्दिष्ट किया जाता है काम नहीं करता है

संबंधित मुद्दे