Conditional Statements (if, else, switch) in c# In Hindi

Conditional Statements (if, else, switch) in c# In Hindi

C# प्रोग्रामिंग लैंग्वेज में कंडीशनल स्टेटमेंट एक प्रोग्राम के डिफ़ॉल्ट फ्लो स्ट्रक्चर को किसी पर्टिकुलर स्पेसिफिक प्रोग्राम लॉजिक एक्सप्रेशन कंडीशन के आधार पर डिसीजन क्रिएट करने में हेल्प करते हैं। C# प्रोग्रामिंग में मुख्य रूप से यूज़ होने वाले पॉपुलर कंडीशनल कंस्ट्रक्ट स्टेटमेंट हैं. जिसमे, if, else if, else स्टेटमेंट, और switch ब्लॉक स्टेटमेंट फीचर्स है।

Conditional Statements (if, else, switch) in c# In Hindi

 if, else if, and else statement concepts in the C# programming.

C# प्रोग्राम में यूजर डिफाइन if स्टेटमेंट पहले किसी प्रोग्राम कंडीशन एक्सप्रेशन को इवैल्यूएट या एनालाइज करता है, और यदि इसमें यूजर डिफाइन इफ कंडीशन एक्सप्रेशन true है, तो इफ स्टेटमेंट रिलेटेड प्रोग्राम सोर्स कोड ब्लॉक को एग्जीक्यूट करता है। अन्यथा यह मौजूदा प्रोग्राम में else स्टेटमेंट के एक ब्लॉक कोड को एग्जीक्यूट करता है. यदि यहाँ if कंडीशन एक्सप्रेशन false है। तो else if स्टेटमेंट एक के बाद एक मल्टीप्ल अवेलेबल  कंडीशन को टेस्ट करता है, जब तक की मौजूदा प्रोग्राम में कोई ब्लॉक ट्रू या फाल्स न हो जाए।

If, else if, and else statement syntax in C#.

if (condition)

{

    // related program Code will be executed, when if condition is true

}

else if (nextCondition)

{

    // here it executes program Code, when if next condition is true

}

else

{

    // here it runs else statement Code, when above if all conditions are in false state

}

Example of if, else if, and else statements in C#.

using System;

class IfElseifElseSt

{

    static void Main()

    {

        int integer = 1;

        if (integer > 0)

        {

            Console.WriteLine(“Positive integer value found”);

        }

        else if (integer < 0)

        {

            Console.WriteLine(“Negative integer value found”);

        }

        else

        {

            Console.WriteLine(“Zero value found”);

        }

    }

}

Switch Statement in C# Programming.

C# प्रोग्रामिंग लैंग्वेज में स्विच स्टेटमेंट का यूज़ किसी यूजर डिफाइन डिक्लेअर प्रोग्राम वेरिएबल को मल्टीप्ल पॉसिबल पोटेंशियल वैल्यू फाइंड या टेस्ट करने में किया जाता है। स्विच स्टेटमेंट मुख्य रूप से if-else स्टेटमेंट चेन की कम्पेरिजन में मल्टीप्ल यूजर डिफाइन प्रोग्राम एक्सप्रेशन कंडीशन के लिए इजी आर्डर में ब्लॉक फॉर्मेट में रीड किया जा सकने वाला एक एफ्फिसिएंट स्टेटमेंट होता है।

Switch Statement in C# syntax.

switch (expression)

{

    case test 1:

        // here program source Code to be execute if expression is == test1

        break;

    case test 2:

        // here program source Code to be execute if expression == test2

        break;

    case test 3:

        // here program source Code to be execute if expression == test3

        break;

    default:

        // default statement only run when all above statement are false or above source Code if no any case matches

        break;

}

Switch Statement example in C#.

using System;

class SwitchStatement

{

    static void Main()

    {

        int car = 2;

        switch (car)

        {

            case 1:

                Console.WriteLine(“Toyota Fortuner”);

                break;

            case 2:

                Console.WriteLine(“Tata Punch”);

                break;

            case 3:

                Console.WriteLine(“Hyundai Creta”);

                break;

            case 4:

                Console.WriteLine(“Maruti Suzuki Dzire”);

                break;

           case 5:

                Console.WriteLine(“Mahindra Scorpio”);

                break;

            default:

                Console.WriteLine(“Invalid car selection”);

                break;

        }

    }

}

Switch Expression Statement/C# 8.0+ in C#.

C# 8.0 वर्जन में एक ज़्यादा छोटा स्विच एक्सप्रेशन सिंटैक्स को पेश किया गया है, जिसमे C# प्रोग्रामर को लार्ज लेंग्थी स्विच स्टेटमेंट इफ स्टेटमेंट की तरह नए स्विच ब्लॉक स्टेटमेंट में आप एक छोटा लेकिन इफेक्टिव स्विच स्टेटमेंट को यूज़ कर सकते है.

using System;

string courseName = course switch

{

    1 => “C# Programming”,

    2 => “Java”,

    3 => “Python”,

    4 => “Javascript”,

    5 => “Matlab”,

    _ => “Invalid course choice” // hare it is the Default case

};

Console.WriteLine(courseName);

Group selection of If Else if, Else statements with Switch statement example in C# program.

using System;

class IfslesifelseWithSwitch

{

    static void Main()

    {

        // here we use single IF statement

        int integer = 1;

        if (integer > 0)

        {

            Console.WriteLine(“checked value is positive”);

        }

        // here we use IF with ELSE statement

        int age =22;

        if (age >= 21)

        {

            Console.WriteLine(“You are mature”);

        }

        else

        {

            Console.WriteLine(“You are not mature”);

        }

        // here we use IF ELSE IF with ELSE statement

        int total = 91;

        if (total >= 90 && total <=100)

        {

            Console.WriteLine(“Grade A”);

        }

        else if (total >= 70 && total <= 85)

        {

            Console.WriteLine(“Grade B”);

        }

        else if (total >= 50 && total <= 65)

        {

            Console.WriteLine(“Grade C”);

        }

        else

        {

            Console.WriteLine(“Fail”);

        }

        // here we use SWITCH statement

        int laptop = 4;

        switch (laptop)

        {

            case 1:

                Console.WriteLine(“Macbok Pro”);

                break;

            case 2:

                Console.WriteLine(“Hp Pavilion”);

                break;

            case 3:

                Console.WriteLine(“Dell Alienware”);

                break;

            case 4:

                Console.WriteLine(“Lenovo Idepad”);

                break;

            case 5:

                Console.WriteLine(“Asus Rog”);

                break;

            default:

                Console.WriteLine(“Invalid Laptop Selection”);

                break;

        }

    }

}

Some special features to remember in C#.

  • C# प्रोग्राम में अधिक कॉम्प्लेक्स प्रोग्रामिंग लॉजिक स्ट्रक्चर के लिए if-else ब्लॉक स्टेटमेंट का ही यूज़ करें।
  • बहुत अधिक प्रोग्राम एक्सप्रेशन कॉम्प्लेक्स या रेंज-बेस्ड कंडीशन के लिए if-else स्टेटमेंट ही एक बेहतर चॉइस है।

Use the switch statement for fixed values ​​in C# programming.

C# प्रोग्राम में किसी यूजर डिफाइन प्रोग्राम वेरिएबल को मल्टीप्ल इंडिविजुअल वैल्यू के अगेंस्ट चेक या टेस्ट करते समय स्विच स्टेटमेंट का यूज़ बेहतर चॉइस होता है।

Always use a break in a switch statement.

स्विच स्टेटमेंट में ब्रेक कीवर्ड को यूज़ न करने से प्रोग्राम में “फॉल-थ्रू” लॉजिक डेवलप हो सकता है, जिससे बिना रुके आपके स्विच स्टेटमेंट कंटिन्यू एक्सेक्यूट हो जाएंगे।

Switch statement default block.

C# प्रोग्राम में if-else और स्विच दोनों ब्लॉक स्टेटमेंट में डिफ़ॉल्ट या कैच-ऑल कंडीशन के लिए एसेंशियल होता है। जब इन दोनों में सभी कंडीशन एक्सप्रेशन फाल्स हो जाते है. तब डिफ़ॉल्ट स्टेटमेंट यहाँ रन होता है.

Leave a Reply