C# System Type

C# System Type: चूंकि C# में Primary Data Type जैसा कुछ होता ही नहीं है, बल्कि जो कुछ होता है, वह Type या Class ही होता है, इसलिए विभिन्न प्रकार के Primary Data Type को बेहतर तरीके से Handle करने के लिए C# जो Extra Functionalities यानी PropertiesMethods Provide करता है, उनके बारे में बेहतर तरीके से समझना हमारे लिए Professional Development के समय काफी उपयोगी साबित होता है।

तो चलिए, इन Primary Data Type की Classes द्वारा Provide की जाने वाली Special PropertiesMethods के बारे में थोडा Detail से समझते हैं।

Data Members of Integer Data Types (Classes)

C# में मूल रूप से System.int16, System.int32System.int64 तीन Types हैं, जो कि C# के short, intlong Shorthand Data Types को Represent करते हैं। इन तीनों ही Primary Data Types की Classes में MaxValueMinValue नाम की दो Public Properties हैं, जिनका प्रयोग करके हम इन Data Types के Data Store करने की न्‍यूनतम व अधिकतम Range का पता लगा सकते हैं। जैसे:

// File Name: SystemTypesIntegerRange.cs
using System;

namespace CSharpFundamentals
{
    class SystemTypesIntegerRange
    {
        private static void Main(string[] args)
        {
            Console.WriteLine("Max of short: {0}", short.MaxValue);
            Console.WriteLine("Min of short: {0}\n", short.MinValue);

            Console.WriteLine("Max of int: {0}", int.MaxValue);
            Console.WriteLine("Min of int: {0}\n", int.MinValue);

            Console.WriteLine("Max of long: {0}", long.MaxValue);
            Console.WriteLine("Min of long: {0}\n", long.MinValue);
        }
    }
}

// Output:
   Max of short: 32767
   Min of short: -32768

   Max of int: 2147483647
   Min of int: -2147483648

   Max of long: 9223372036854775807
   Min of long: -9223372036854775808

Data Members of Unsigned Integer Data Types (Classes)

C# में मूल रूप से System.UInt16, System.UInt32System.UInt64 तीन Types हैं, जो कि C# के ushort, uintulong Shorthand Data Types को Represent करते हैं। इन तीनों ही Primary Data Types की Classes में भी MaxValueMinValue नाम की दो Public Properties हैं, जिनका प्रयोग करके हम इन Data Types के Data Store करने की न्‍यूनतम व अधिकतम Range का पता लगा सकते हैं। जैसे:

// File Name: SystemTypesIntegerRange.cs
using System;

namespace CSharpFundamentals
{
    class SystemTypesUnsignedIntegerRange
    {
        private static void Main(string[] args)
        {
            Console.WriteLine("Min of short: {0}", ushort.MinValue);
            Console.WriteLine("Max of short: {0}\n", ushort.MaxValue);

            Console.WriteLine("Min of int: {0}", uint.MinValue);
            Console.WriteLine("Max of int: {0}\n", uint.MaxValue);

            Console.WriteLine("Min of long: {0}", ulong.MinValue);
            Console.WriteLine("Max of long: {0}\n", ulong.MaxValue);
        }
    }
}

// Output:
   Min of short: 0
   Max of short: 65535

   Min of int: 0
   Max of int: 4294967295

   Min of long: 0
   Max of long: 18446744073709551615

Data Members of Real Number Data Types (Classes)

C# में Real Numbers Data Types को Handle करने के लिए मूल रूप से System.Single, System.DoubleSystem.Decimal नाम के तीन Types हैं, जो कि C# के float, doubledecimal Shorthand Data Types को Represent करते हैं। इन तीनों ही Primary Data Types की Classes में भी MaxValueMinValue नाम की दो Public Properties होती है।

जबकि floatdouble के साथ Epsilon, NaN, NegativeInfinityPositiveInfinity नाम की चार और Public Properties हैं, जिनका प्रयोग करके हम इस बात का भी पता लगा सकते हैं कि कोई Data Negative Infinity या Positive Infinity है या नहीं। अथवा NaN इस बात को Represent करता है कि Specified Data कोई Numeric Value है या नहीं जबकि Epsilon किसी संख्‍या की न्‍यूनतम Positive संख्‍या को Represent करता है।

जबकि decimal Data Type के साथ MinusOne, OneZero नाम की तीन और Properties हैं, जो कि क्रमश% -1, 1 व 0 को Represent करते हैं। इन सभी Properties को हम निम्नानुसार तरीके से Use कर सकते हैं:

// File Name: SystemTypesRealNumberProperties.cs
using System;

namespace CSharpFundamentals
{
    class SystemTypesRealNumberProperties
    {
        private static void Main(string[] args)
        {
            Console.WriteLine("Min of float: {0}", float.MinValue);
            Console.WriteLine("Max of float: {0}", float.MaxValue);
            Console.WriteLine("Epsilon of float: {0}", float.Epsilon);
            Console.WriteLine("NegativeInfinity of float: {0}", float.NegativeInfinity);
            Console.WriteLine("PositiveInfinity of float: {0}\n", float.PositiveInfinity);

            Console.WriteLine("Min of double: {0}", double.MinValue);
            Console.WriteLine("Max of double: {0}", double.MaxValue);
            Console.WriteLine("Epsilon of double: {0}", double.Epsilon);
            Console.WriteLine("NegativeInfinity of double: {0}", double.NegativeInfinity);
            Console.WriteLine("PositiveInfinity of double: {0}\n", double.PositiveInfinity);

            Console.WriteLine("Min of decimal: {0}", decimal.MinValue);
            Console.WriteLine("Max of decimal: {0}", decimal.MaxValue);
            Console.WriteLine("MinusOne of decimal: {0}", decimal.MinusOne);
            Console.WriteLine("One of decimal: {0}", decimal.One);
            Console.WriteLine("Zero of decimal: {0}\n", decimal.Zero);
        }
    }
}

// Output:
   Min of float: -3.402823E+38
   Max of float: 3.402823E+38
   Epsilon of float: 1.401298E-45
   NegativeInfinity of float: -Infinity
   PositiveInfinity of float: Infinity

   Min of double: -1.79769313486232E+308
   Max of double: 1.79769313486232E+308
   Epsilon of double: 4.94065645841247E-324
   NegativeInfinity of double: -Infinity
   PositiveInfinity of double: Infinity

   Min of decimal: -79228162514264337593543950335
   Max of decimal: 79228162514264337593543950335
   MinusOne of decimal: -1
   One of decimal: 1
   Zero of decimal: 0

Data Members of Boolean Data Type (Class)

C# में Boolean Data Type को Handle करने के लिए मूल रूप से System.Boolean नाम के Type को Define किया गया है, जिसमें TrueStringFalseString नाम की दो Public व Static Properties हैं। इस Data Type को C# के bool Shorthand Data Type द्वारा Represent करते हैं। इस Data Type की इन दोनों Properties को निम्नानुसार Use किया जा सकता है:

// File Name: SystemTypeBoolean.cs
using System;

namespace CSharpFundamentals
{
    class SystemTypeBoolean
    {
        private static void Main(string[] args)
        {
            Console.WriteLine("bool.TrueString: {0}", bool.TrueString);
            Console.WriteLine("bool.FalseString: {0}", bool.FalseString);
        }
    }
}

// Output:
   bool.TrueString: True
   bool.FalseString: False

Data Members of Char Data Type (Class)

C# में Textual Data को string या char Keywords द्वारा Represent किया जाता है, जो कि क्रमश System.StringSystem.Char नाम के Types के Shorthand Notations हैं और दोनों ही Unicode Characters को Handle करते हैं। System.Char Type भी हमें MinValueMaxValue नाम की दो Public Properties Provide करता है।

लेकिन ये Class हमें Character Related विभिन्न प्रकार के Operations Perform करने के लिए बहुत सारे Methods Provide करता है, जिनमें से ज्यादा Methods “Is****” Methods हैं, जो Argument के रूप में Specified Character के विषय में True या False के रूप में महत्वपूर्ण जानकारियां Provide करते हैं। इस Class द्वारा Provided विभिन्न Methods में से कुछ को हम निम्नानुसार Use कर सकते हैं:

// File Name: SystemTypeChar.cs
using System;

namespace CSharpFundamentals
{
    class SystemTypeChar
    {
        private static void Main(string[] args)
        {
            Console.WriteLine("char.IsDigit('a'): {0}", char.IsDigit('a'));
            Console.WriteLine("char.IsDigit('1'): {0}\n", char.IsDigit('1'));

            Console.WriteLine("char.IsLetter('a'): {0}", char.IsLetter('a'));
            Console.WriteLine("char.IsLetter('1'): {0}\n", char.IsLetter('1'));

            Console.WriteLine("char.IsWhiteSpace(' '): {0}", char.IsWhiteSpace(' '));
            Console.WriteLine("char.IsWhiteSpace('H'): {0}\n", char.IsWhiteSpace('H'));

            Console.WriteLine("char.IsPunctuation('a'): {0}", char.IsPunctuation('a'));
            Console.WriteLine("char.IsPunctuation('?'): {0}\n", char.IsPunctuation('?'));

            Console.WriteLine("char.IsUpper('A'): {0}", char.IsUpper('A'));
            Console.WriteLine("char.IsUpper('a'): {0}\n", char.IsUpper('a'));

            Console.WriteLine("char.IsLower('A'): {0}", char.IsLower('A'));
            Console.WriteLine("char.IsLower('a'): {0}\n", char.IsLower('a'));

            Console.WriteLine("char.IsNumber('A'): {0}", char.IsNumber('A'));
            Console.WriteLine("char.IsNumber('1'): {0}\n", char.IsNumber('1'));
        }
    }
}

// Output:
   char.IsDigit('a'): False
   char.IsDigit('1'): True

   char.IsLetter('a'): True
   char.IsLetter('1'): False

   char.IsWhiteSpace(' '): True
   char.IsWhiteSpace('H'): False

   char.IsPunctuation('a'): False
   char.IsPunctuation('?'): True

   char.IsUpper('A'): True
   char.IsUpper('a'): False

   char.IsLower('A'): False
   char.IsLower('a'): True

   char.IsNumber('A'): False
   char.IsNumber('1'): True

जैसाकि हम उपरोक्त उदाहरण द्वारा समझ सकते हैं कि विभिन्न System.Char Methods में Argument के रूप में केवल एक Single Character को ही Specify किया है, क्योंकि सभी System.Char Methods केवल Single Character पर काम करते हैं।

लेकिन इन्हीं सारे Methods को हम किसी String के साथ भी Use कर सकते हैं और जब हम इन Methods को किसी String के साथ Use करते हैं, तब इन सभी Methods में पहले Argument के रूप में वह String Specify करते हैं, जिस पर Method को Operation Perform करना होता है। जबकि दूसरे Argument के रूप में वह Index Number Specify करना होता है, जो कि String में उस Character की Zero Based Position को Indicate करता है, जिस पर Method को Operation Perform करना है। जैसे:

// File Name: SystemTypeChar.cs
using System;

namespace CSharpFundamentals
{
    class SystemTypeCharMethodsWith2Arguments
    {
        private static void Main(string[] args)
        {
            string msg = "Hello World! 1#";
            Console.WriteLine("char.IsDigit at Position 3: {0}", char.IsDigit(msg, 3));
            Console.WriteLine("char.IsDigit at Position 13: {0}\n", char.IsDigit(msg, 13));

            Console.WriteLine("char.IsLetter at Position 0: {0}", char.IsLetter(msg, 0));
            Console.WriteLine("char.IsLetter at Position 5: {0}\n", char.IsLetter(msg, 5));

            Console.WriteLine("char.IsWhiteSpace at Position 5: {0}", char.IsWhiteSpace(msg, 5));
            Console.WriteLine("char.IsWhiteSpace at Position 6: {0}\n", char.IsWhiteSpace(msg, 6));

            Console.WriteLine("char.IsPunctuation at Location 11: {0}", char.IsPunctuation(msg, 11));
            Console.WriteLine("char.IsPunctuation at Location 12: {0}\n",char.IsPunctuation(msg,12));

            Console.WriteLine("char.IsUpper at Location 6: {0}", char.IsUpper(msg, 6));
            Console.WriteLine("char.IsUpper at Location 7: {0}\n", char.IsUpper(msg, 7));

            Console.WriteLine("char.IsLower at Location 6: {0}", char.IsLower(msg, 6));
            Console.WriteLine("char.IsLower at Location 7: {0}\n", char.IsLower(msg, 7));

            Console.WriteLine("char.IsNumber at Location 13: {0}", char.IsNumber(msg, 13));
            Console.WriteLine("char.IsNumber at Location 12: {0}", char.IsNumber(msg, 12));
        }
    }
}

// Output:
   char.IsDigit at Position 3: False
   char.IsDigit at Position 13: True

   char.IsLetter at Position 0: True
   char.IsLetter at Position 5: False

   char.IsWhiteSpace at Position 5: True
   char.IsWhiteSpace at Position 6: False

   char.IsPunctuation at Location 11: True
   char.IsPunctuation at Location 12: False

   char.IsUpper at Location 6: True
   char.IsUpper at Location 7: False

   char.IsLower at Location 6: False
   char.IsLower at Location 7: True

   char.IsNumber at Location 13: True
   char.IsNumber at Location 12: False

इस Program में हमने msg नाम का एक String Type Create किया है जिसमें Value के रूप में “Hello World!” String Value को Store किया है और System.Char Related विभिन्न Methods को इस String के किसी Particular Character पर Apply करने के लिए सभी Methods में दूसरे Argument में उस Index Position को Specify किया है, जिस पर Method को Apply करना है।

C# में भी C/C++ की तरह ही String को एक One-Dimensional Character Array की तरह माना जा सकता है। इसलिए हमारी String msg के पहले Character का Index Number या Position 0] दूसरे Character का Index Number 1, तीसरे Character का Index Number 2 है व यही क्रम आगे भी जारी रहता है। इस तरह से यदि हम यदि हम हमारे Program के निम्न Code के Output को समझें%

Console.WriteLine(“char.IsDigit at Position 3: {0}”, char.IsDigit(msg, 3));
Console.WriteLine(“char.IsDigit at Position 13: {0}\n”, char.IsDigit(msg, 13));

तो IsDigit() Method में दूसरे Argument के रूप में हमने Index Position का मान 3 Specify किया है, जो कि हमारे msg नाम के Variable में Stored String के चौथे Character (Hello World! 1#) “l” को Represent करता है जो कि एक Character है, Digit नहीं। इसलिए इस Code का पहला Statement Output के रूप में निम्नानुसार False मान Return करता है:

char.IsDigit at Position 3: False

जबकि उपरोक्त Code के दूसरे Statement में Specified IsDigit() Method के दूसरे Argument के रूप में हमने मान 13 Specify किया है, जो कि हमारे msg नाम के Variable में Stored String के तेरहवें Character (Hello World! 1#) “1” को Represent करता है जो कि एक Digit है। इसलिए ये दूसरा Statement Output के रूप में निम्नानुसार True मान Return करता है:

char.IsDigit at Position 13: True

इसी तरह से अन्‍य System.Char Methods भी Execute होते हैं और Specified String की Particular Index Position पर स्थित Character पर Apply होकर अपना Effect दिखाते हैं।

Value Parsing from String Data

C# में जब हम GUI Application Develop करते हैं, तब विभिन्न प्रकार के Controls जैसे कि Textbox, List, Combo आदि Use करते हैं। इन Controls में हम यदि कोई Numerical Value भी लिखते हैं, तो वह Numerical Value भी String की तरह ही Treat होती हैं।

इसलिए इस प्रकार की String Formatted Text से Value को अलग करना पडता है या सरल शब्दों में कहें, तो Text को Number में Convert करना पडता है, तभी हम इन Values के साथ किसी प्रकार की Numerical Calculation Perform कर सकते हैं।

इस जरूरत को पूरा करने के लिए .NET Framework हमें Parse() नाम का एक Method Provide करता है, जिसे हम निम्नानुसार तरीके से विभिन्न Primary Data Types के Numerical Text Data के साथ Use करते हुए उन्हें Numerical Data में Convert करने हेतु Use कर सकते हैं:

// File Name: SystemTypeParseMethod.cs
using System;

namespace CSharpFundamentals
{
    class SystemTypeParseMethod
    {
        private static void Main(string[] args)
        {
            bool b = bool.Parse("TRUE");
            Console.WriteLine("Value of b: {0}", b);

            double d = double.Parse("990.8004");
            Console.WriteLine("Value of d: {0}", d);

            int i = int.Parse("6");
            Console.WriteLine("Value of i: {0}", i);

            char c = Char.Parse("x");
            Console.WriteLine("Value of c: {0}", c);
        }
    }
}

// Output:
   Value of b: True
   Value of d: 990.8004
   Value of i: 6
   Value of c: x

C# in Hindiये Article इस वेबसाईट पर Selling हेतु उपलब्‍ध EBook C#.NET in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी रहा, तो निश्चित रूप से ये पुस्तक भी आपके लिए काफी उपयोगी साबित होगी। 

C#.NET in Hindi | Page:908 | Format: PDF

BUY NOW GET DEMO REVIEWS