C# - Control Statements in Hindi




दोस्तों इस chapter में हम C# Control Statements के बारे में जानेंगे तो चलिए शुरू करते है. C, C++ व Java की तरह ही C# में भी different types की control statements को define किया गया है, इनकी सहायता program control को program के एक execution point से दूसरे execution point पर transfer किया जाता है।

Program flow को भी control किया जाता है. Basic रूप से किसी भी programming Language की तरह ही C# में भी कंडीशनल, branching व Looping स्टेटमेंट्स होते हैं. और सामान्‍यत ये statements सभी प्रोग्रामिंग languages में समान ही होते हैं।

C# If statement

C# if statement कंडीशन का tests करता है. यदि स्थिति सत्य है तो यह execute करता जाता है. if statement एक control statement है जिसका उपयोग एक विशेष condition को test करने के लिए किया जाता है. दोस्तों इसमें condition को केवल एक ही बार execute किया जाता है जब कंडीशन सत्य होती है.

Syntax

if(condition){  
//code to be executed  
}  

C# IF-else Statement

C# if-else स्टेटमेंट भी कंडीशन का tests करता है। if-else स्टेटमेंट का उपयोग किया जाता है. यदि कंडीशन सत्य है तो if statement को execute किया जाता है अगर कंडीशन असत्य है तो else statement को execute किया जाता है.

Syntax

if(condition){  
//code if condition is true  
}else{  
//code if condition is false  
}  

C# Switch Statements

Switch statement एक multi-way शाखा statement है. यह statement भी एक सिलेक्शन statement जो कि एक program के execution के लिए विभिन्न paths को define करता है. यह if-else statement के लिए विकल्प के तौर पर कार्य करता है.

Example

switch(variable)
{
case constant 1;
statements(s);
break:
case constant 2;
statement(s);
break;
case constant 3;
statement(s);
break;
———–
default
statement(s);
}