Type Conversion in C# in Hindi – C# में टाइप कन्वर्शन क्या है?

हेल्लो दोस्तों! आज हम इस पोस्ट में Type Conversion in C# in Hindi (C# में टाइप कन्वर्शन क्या है? ) के बारें में पढेंगे और इसके types को भी जानेंगे. इसे आप पूरा पढ़िए, यह आपको आसानी से समझ में आ जायेगा. तो चलिए शुरू करते हैं:-

Type Conversion in C# in Hindi

C# में, Type Conversion एक प्रक्रिया है जिसमें data के एक type को दूसरे type में convert किया जाता है. इसे Type Casting भी कहते है.

Type Conversion तब होता है जब एक data type की value को दूसरे data type को assign की जाती है. यदि data type अनुकूल (compatible) होता है तो C# अपने आप ही Type Conversion कर देता है. परन्तु यदि वह compatible नहीं होता है तो हमें data type को manually convert करना पड़ता है.

उदाहरण के लिए – long variable को int value प्रदान करना.

Type Casting दो प्रकार की होती है:-

  1. Implicit Type Conversion
  2. Explicit Type Conversion

Implicit Type Conversion

इसे automatic type conversion भी कहते है क्योंकि इसमें conversion अपने-आप होता है. इस conversion को C# के द्वारा type-safe manner में किया जाता है.

यह तब होता है जब:-

  • जब दो data types अनुकूल (compatible) होते हैं.
  • जब हम छोटे data type की value को बड़े data type को assign करते हैं.

नीचे दी गयी table में C# के द्वारा support किये जाने वाले implicit type conversion दिए गये हैं:-

Convert from Data TypeConvert to Data Type
byteshort, int, long, float, double
shortint, long, float, double
intlong, float, double
longfloat, double
floatdouble

इसका example

using System; 
namespace Casting{ 
  
class Test { 
  
// Main Method 
public static void Main(String []args) 
{ 
int i = 50;  
              
// automatic type conversion 
long l = i; 
 
// automatic type conversion 
float f = l; 
            
// Display Result 
Console.WriteLine("Int value "  +i); 
Console.WriteLine("Long value "  +l); 
Console.WriteLine("Float value "  +f); 
        } 
} 
} 

इसका आउटपुट

Int value 50
Long value 50
Float value 50

Explicit Type Conversion

Explicit Type Conversion को manual type conversion भी कहते है क्योंकि इसमें data type को manually कन्वर्ट किया जाता है. इसके लिए users के द्वारा pre-defined functions का प्रयोग किया जाता है.

इसे तब किया जाता है जब:-

  • जब हम बड़े data type की value को छोटे data type में assign  करना चाहते हैं.
  • जब डाटा टाइप compatible नहीं होता.

Example

using System;

namespace TypeConversion{
class ExplicitConversion {
static void Main(string[] args) {
double d = 4321.55; 
int i;
         
// cast double to int.
i = (int)d;
Console.WriteLine(i);
Console.ReadKey();
}
}
}

इसका आउटपुट – 4321

Conversion Methods in C# in Hindi

C# में निम्नलिखित conversion methods होते हैं:-

Methods Description
ToBoolean यह type को एक boolean value में convert कर देता है.
ToByte यह type को एक byte में convert करता है.
ToChar यह एक type को एक single Unicode character में बदलता है..
ToDateTime यह एक type को date-time structures में बदलता है.
ToDecimal यह एक floating point या integer type को एक decimal type में convert करता है.
ToDouble यह एक type को double में convert करता है.
ToInt16 यह एक type को एक 16-bit integer में बदलता है.
ToInt32 यह एक type को एक 32-bit integer में convert करता है.
ToInt64 यह एक type को एक 64-bit integer में convert करता है.
ToSbyte यह type को एक signed byte type में convert करता है.
ToSingle यह एक type को एक छोटे floating point number में convert करता है.
ToString यह एक type को एक string में बदल देता है.
ToType यह एक type को एक specified type में बदल देता है.
ToUInt16 यह एक type को एक unsigned int type में बदल देता है.
ToUInt32 यह एक type को एक unsigned long type में बदल देता है.
ToUInt64 यह एक type को एक unsigned big integer में बदल देता है.

References:- https://www.tutorialspoint.com/csharp/csharp_type_conversion.htm

type conversion in c# in Hindi

निवेदन:- अगर आपके लिए Type Conversion in C# in Hindi का यह आर्टिकल उपयोगी रहा हो तो इसे अपने friends और classmates के साथ अवश्य share कीजिये. अगर आपके .net programming से related कोई सवाल हो तो उसे नीचे comment करके बताइए. Thanks.

Leave a Comment