VB.NET में Operators क्या है और उसके प्रकारों को Programs सहित सीखे

What is Operators in VB.NET in Hindi


Operators एक Symbol है जो Data पर विभिन्न 
Operations जैसे arithmetic calculations, logical evaluations, और comparisons आदि Perform करता है।

VB.NET मे हमारे पास जो Operators की एक बड़ी श्रृंखला है विभिन्न आवश्यकता को पूरी करता है
हम Operators को नीचे दिए Example से और समझने का प्रयास करेंगे

Example
2+3 = 5
यहां पर + और = का चिन्ह Operator है जबकि 2 और 3 Operands है Operator , Compiler को यह बताता है कि Operands पर क्या Operations Perform करना है

Types of Operators in VB.NET in Hindi - VB.NET में ऑपरेटर्स के प्रकार

VB.NET में निम्न प्रकार के Operators पाए जाते है
1) Arithmetic operators
2) Comparison operators
3) Logical operators 
4) Assignment operators 
5) Bitwise operators 

Operator Symbol
OperatorArithmetic Symbol+, -, *, /,\, Mod
OperatorComparison Symbol=,<, <=, > ,>=, <>,Like, Is
OperatorAssignment Symbol =
OperatorLogical/Bitwise Symbol And, or, Not, Xor, AndAlso, OrElse, IsFalse, IsTrue
OperatorBit Shift Symbol<<, >>
OperatorMiscellaneous SymbolAddresOf, GetType

Arithmetic operators

Arithmetic operators का प्रयोग Basic Mathematical Operations या Calculation Perform करने मे होता है

Operators Symbol
+,  -,  *,  /, \,  Mod Operators आते है

Program for Arithmetic Operator 
Module Arithmeticoperators
Sub Main ()
Dim a,b,c As Integer
a= 50
b =20
c= a+b
Console.WriteLine ("Addition of a and b is :"&c)
c= a-b
Console.WriteLine ("Substraction of a and b is :"&c)
c= a*b
Console.WriteLine ("Multiplication of a and b is :"&c)
c=a/b
Console.WriteLine ("Division of a and b is :"&c)
c= a mod b
Console.WriteLine ("Mod of a and b is :"&c)
Console.ReadLine()
End Sub
End Module

Output:

Addition of a and b is :70
Substraction of a and b is :30
Multiplication of a and b is :1000
Division of a and b is :2
Mod of a and b is :10

Comparison/Relational operators

Comparison operators का प्रयोग Values की तुलना करने और तुलना के आधार पर Boolean Result (True या False) Return करने में होता है
इन Operators का प्रयोग अक्सर conditional statements और sorting algorithms में होता है

Program for Comparison Operators

Module Comparisonoperators
Sub Main()
Dim a As Integer = 17
Dim b As Integer = 23
Dim result As Boolean
result = a > b
Console.WriteLine("a>b is:" & result)
result = a < b
Console.WriteLine("a<b is:" & result)
result = a <= b
Console.WriteLine("a<=b is: " & result)
result = a = b
Console.WriteLine("a=b is : " & result)
result = a <> b
Console.WriteLine("a<> b is:" & result)
Console.ReadLine()
    End Sub
End Module


Output:

a>b is : False
a<b is : True
a>=b is:False
a<=b is: True
a=b is : False
a<> b is:True

Logical operators

Logical operators का प्रयोग किसी Condition या Boolean Values पर logical operations Perform करने में होता है

इस मे निम्न Operators आते हैं

1) And Operator (`And`):
And operator में दो Operands होते है तथा इसमें दोनों Operands True है तो Result भी True होगा तथा दोनों Operands में कोई एक Operands भी False है तो Result False ही होगा 

2) Or Operator (`Or`):
Or Operator में भी And की भांति दो Operands होते है इसमें यदि दोनो Operands False है तभी Result False होगा अन्यथा किसी एक Operands के True होने से Result True होगा 

3) Not Operator (`Not`):
 इसमें एक ही Operand होते है जब यह Operand True होता है तब Result False होगा और जब यह Operand False होगा Result True होता है  

4) Xor Operator (`Xor`):
 इसमें Result तभी True होगा जब दोनों Operands में से कोई भी एक Operand True है जबकि यदि दोनो Operands True या False है तब Result हमेशा False आयेगा

5) AndAlso Operator:
यह logical "And" Operator के समान कार्य करता है लेकिन Short Circuiting के साथ अर्थात इसमें यदि First Condition False है तो वह दूसरे Condition को मूल्यांकित(Check) नहीं करता 

6) OrElse Operator:
यह logical "Or" Operator के समान कार्य करता है लेकिन Short Circuiting के साथ अर्थात इसमें यदि First Condition True है तो वह दूसरे Condition को मूल्यांकित(Check) नहीं करता 

7) IsFalse: 
यह निर्धारित करता है कि कोई Expression गलत है या नहीं।

8) IsTrue :
यह निर्धारित करता है कि कोई Expression सही है या नहीं

Program for Logical Operators
Module Logicaloperators
Sub Main()
Dim a As Integer = 10
Dim b As Integer = 17
Console.WriteLine( a> 6 And b<18)
Console.WriteLine(a>6 or b<17)
Console.WriteLine(not b>18)
End Sub
End Module
 

Output:

True
True
True

Assignment operators

Assignment operators का प्रयोग Variables को Value Assign करने में होता है  

Program for Assignment Operators 
Module AssignmentOperator
    Sub Main()
        Dim a As Integer = 15
        Dim b As Integer
       b = a      
Console.WriteLine("Value of b is : " & b)
Console.ReadLine()
    End Sub
End Module
Output:
Value of b is : 15

Bitwise Operators

Bitwise operators का प्रयोग Bit Level (0 या 1) Operation Perform करने में होता है इस Operator का प्रयोग सामान्यत: low-level programming और binary data के साथ कार्य करने में होता है 
Program for Bitwise Operators

Module Bitwiseoperators
Sub Main()
Dim x As Integer = 3
Dim y As Integer = 5
Dim result As Integer
Dim result1 As Integer
result = x And y
Console.WriteLine("Bitwise Result of x And y is : " & result)
result = x or y
Console.WriteLine("Bitwise Result of x or y is : " & result)
result = x XOR y
Console.WriteLine("Bitwise Result of x XOR y is : " & result)
result1 = Not x
Console.WriteLine("Bitwise Result of Not x is : " & result1)
Console.ReadLine()
End Sub
End Module


Output:
Bitwise Result of x And y is : 1
Bitwise Result of x or y is : 7
Bitwise Result of x XOR y is : 6
Bitwise Result of Not x is : 4

ExplanatIon 
1) And Operator:
दो Numbers के bits की तुलना करता है यदि दोनो bits 1 है तो Result 1 bit होगा अन्यथा 0 bit होगा
3 के लिए Binary Number   011
5 के लिए Binary Number   101
                                            -------
                       3 And 5        001  
1 Number के लिए Binary Number 001 होता है जैसे Output में दिया गया है

2) Or Operator:
दो Numbers के bits की तुलना करता है यदि दोनो मे से एक bits 1 है तो Result 1 bit होगा और दोनों bits 0 होने पर Result 0 bit होगा
                    
                    011
                    101
                 --------------
                    111
7 Number के लिए Binary Number 111 होता है जैसे Output में दिया गया है

3) Xor Operator
 दो Numbers के bits की तुलना करता है यदि दोनो bits में अंतर होगा है तो Result 1 bit होगा और यदि दोनों bits एक समान होने पर Result 0 bit होगा                 
                    011
                    101
                --------------
                    110
6 Number के लिए Binary Number 110 होता है जैसे Output में दिया गया है

4) Not Operator
यह Number के bits को Flip करता है अर्थात 1 bit को 0 bit में और 0 bit को 1 bit मे         
For Binary Number for 3      011
                                Not 3 is  100
                             
4 Number के लिए Binary Number 100 होता है जैसे Output में दिया गया है

Bit Shift Operators

VB.NET में Bit Shift Operators का प्रयोग Binary Number के Bits को या तो Left या Right Shift करने के लिए किया जाता है
VB.NET में मुख्य दो Bit Shift होते है

1) Left Shift (<<) Operator
Left Shift Operator का उपयोग Binary अनुक्रम को निर्दिष्ट स्थिति के अनुसार बाईं ओर स्थानांतरित करने के लिए किया जाता है।

2) Right Shift (>>) Operator
Right Shift Operator का उपयोग Binary अनुक्रम को निर्दिष्ट स्थिति के अनुसार दाई ओर स्थानांतरित करने के लिए किया जाता है।

Program for Left Shift (<<) Operator 
Module Bitleftshiftoperator
    Sub Main()
 Dim originalnum As Integer = 5

 Dim leftshiftednum As Integer = originalnum<< 3       
  
 Console.WriteLine("Original number: " & originalnum)

Console.WriteLine("Left Shifted Number is : " & leftshiftednum)
        Console.ReadLine()
    End Sub
End Module

Output:
Original number: 5
Left Shifted Number is : 40

Program for Right Shift (>>) Operator
  Module BitrightshiftOperator  
  Sub Main()
Dim originalnum As Integer = 15

Dim rightshiftednum As Integer = originalnum >> 3
  
Console.WriteLine("Original number: " & originalnum)          
  
Console.WriteLine("Right Shifted Number is :"& rightshiftednum))
        Console.ReadLine()
    End Sub
End Module

Output:
Original number: 15
Right Shifted Number is : 1

Miscellaneous Operators 

VB.NET में कई miscellaneous operators है जो arithmetic, comparison, logical और bitwise operations से हटकर अलग विशेष उद्देश्य को पूरा करता है कुछ miscellaneous operator निम्न है
1) AddressOf
2) Await
3) Get Type
4) Function Expression
5) If

AddressOf

AddressOf Operator का प्रयोग एक Method या Function का Memory Address प्राप्त करने में होता है जिसका उपयोग करके हम बाद मे उस Function या Method को call कर सकते हैं

Await

Asynchronous operation में कई Tasks एक साथ Execute किए जाते है और अगले Task के आगे बढ़ने से पहले Program को प्रत्येक Task के पूरे होने का इंतजार करना नही पड़ता 

VB.NET मे Await Operator के साथ asynchronous programming के लिए मज़बूत Support प्रदान करता है  
Await Operators का प्रयोग किसी asynchronous programming के पहले 

यह इंगित करने के लिए किया जाता है कि किसी Task की प्रतीक्षा की जा रही है। और यह Complier को Awaited Task के पूरा होने तक Current Method के Execution को Suspand करने के लिए कहता है।

Await Operators VB.NET में asynchronous programming की आधारशिला है। किसी Task या Method को Call करने से उसके आगे Await Keywords का Use करने से 

यह Compiler को प्रतीक्षित कार्य पूरा होने तक Current Method के Execution को निलंबित करने का निर्देश देता है। इस बीच, Application अन्य कोड को Execute करना जारी रख सकता है 

Get Type

Get Type operator, को 'GetType', Keyword से Represent किया जाता है जो Runtime में एक Object के Type संबन्धित Information को प्राप्त करने की अनुमति देते है इन Information में Type का नाम, Base Type, कार्यान्वित Interface और उससे ज्यादा रहता है  

Function Expression

VB.NET में Function Expression operator को 'Function' keyword से Denote किया जाता है जो आपको Code के अंदर एक functions परिभाषित करने की अनुमति देते है

function expression operator का Syntax 'Function' keyword के साथ शुरू होता है उसके बाद function name, Parameter है तो उसके लिए parentheses का Set और वैकल्पिक Return Type होते है 

Function की body को End Function से Close करते है
इस Operator का प्रयोग एक बड़े Function के अंदर Function को Define करने, Anonymous Function बनाने या एक Variable को Function Assign करने मे भी होता है

 If

VB.NET में If operator का प्रयोग conditional statements के लिए किया जाता है जो आपको Condition Check करने और यदि Condition True है तो एक Value Return करने की तथा Condition False है तो अन्य Value Return करने की अनुमति देते है  

 Related Post