C# fundamentals Part 2
-
Upload
ifour-institute-sustainable-learning -
Category
Technology
-
view
64 -
download
0
Transcript of C# fundamentals Part 2
iFour Consultancy
Basics of .NET
OperatorsControl statementsAccess Modifiers
INDEX
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India
It is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C# has rich set of built-in operators and provides the following types of operators
• Arithmetic Operators• Relational Operators• Logical Operators• Bitwise Operators• Assignment Operators• Misc Operators
Operators
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India
Arithmetic Operators
Operators (cont.)
Operator Description Example(A=10,B=20)+ Adds two operands A + B = 30- Subtracts second operand from the first A - B = -10* Multiplies both operands A * B = 200/ Divides numerator by de-numerator B / A = 2% Modulus Operator and remainder of after an
integer divisionB % A = 0
++ Increment operator increases integer value by one A++ = 11-- Decrement operator decreases integer value by
oneA-- = 9
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India
Relational Operators
Operators (cont.)
Operator Description Example(A=10,B=20)== Checks if the values of two operands are equal or not, if yes then condition
becomes true(A == B) is not true.
!= Checks if the values of two operands are equal or not, if values are not equal then condition becomes true
(A != B) is true
> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true
(A > B) is not true
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true
(A < B) is true
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true
(A >= B) is not true
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true
(A <= B) is true
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India
Logical Operators
Operators (cont.)
Operator Description Example(A=true,B=false)
&& Called Logical AND operator. If both the operands are non zero then condition becomes true
(A && B) is false
|| Called Logical OR Operator. If any of the two operands is non zero then condition becomes true
(A || B) is true
! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false
!(A && B) is true
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India
Bitwise Operators
Operators (cont.)
Operator Description Example(A=60=00111100 B=13=0000 1101)
& Binary AND Operator copies a bit to the result if it exists in both operands (A & B) = 12, 00001100| Binary OR Operator copies a bit if it exists in either operand (A | B) = 61, 0011 1101^ Binary XOR Operator copies the bit if it is set in one operand but not both (A ^ B) = 49, 00110001~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits (~A ) = 61, which is 1100
0011<< Binary Left Shift Operator. The left operands value is moved left by the number of
bits specified by the right operandA << 2 = 240, which is 1111 0000
>> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand
A >> 2 = 15, which is 0000 1111
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India
Assignment Operators
Operators (cont.)
Operator Description Example= Binary AND Operator copies a bit to the result if it exists in both operands. C = A + B assigns value of
A + B into C
+= Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand
C += A is equivalent to C = C + A
-= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand
C-=A is equivalent to C=C-A
*= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand
C *= A is equivalent to C = C * A
/= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand
C /= A is equivalent to C = C / A
%= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand
C %= A is equivalent to C = C % A
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India
Assignment Operators
Operators (cont.)
Operator Description Example<<= Left shift AND assignment operator C <<= 2 is same as C =
C << 2>>= Right shift AND assignment operator C >>= 2 is same as C =
C >> 2&= Bitwise AND assignment operator C &= 2 is same as C = C
& 2^= bitwise exclusive OR and assignment operator C ^= 2 is same as C = C
^ 2%= bitwise inclusive OR and assignment operator C |= 2 is same as C = C
| 2
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India
Statement that determines whether other statements will be executed• if statement decides whether to execute another statement, or decides which of two
statements to execute• If -else :If the boolean expression evaluates to true, then the if block of code is executed,
otherwise else block of code is executed• A switch statement decides which of several statements to execute• for loops are (typically) used to execute the controlled statement a given number of times.• The foreach statement repeats a group of embedded statements for each element in an array
or an object collection that implements• while loops test whether a condition is true before executing the controlled statement• do-while loops test whether a condition is true after executing the controlled statement
Control statements
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India
Public• The public keyword is an access modifier for types and type members. Public access is the most
permissive access level • Accessibility:
• Can be accessed by objects of the class• Can be accessed by derived classes
Private• Private members are accessible only within the body of the class or the struct in which they are
declared• Accessibility:
• Cannot be accessed by object• Cannot be accessed by derived classes
Access Modifiers
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India
Protected• A protected member is accessible from within the class in which it is declared, and from within
any class derived from the class that declared this member • Accessibility:
• Cannot be accessed by object• By derived classes
Internal• Access modifier for types and type members. We can declare a class as internal or its member
as internal. Internal members are accessible only within files in the same assembly• Access is limited exclusively to classes defined within the current project assembly
Access Modifiers
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India
• Accessibility: • In same assembly (public)
• Can be accessed by objects of the class• Can be accessed by derived classes
• In other assembly (internal) • Cannot be accessed by object• Cannot be accessed by derived classes
Protected Internal• The protected internal accessibility means protected OR internal, not protected AND internal• In other words, a protected internal member is accessible from any class in the same assembly,
including derived classes
Access Modifiers
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India
https://www.tutorialspoint.com/csharp/ http://www.c-sharpcorner.com/UploadFile/mkagrahari/introduction-to-object-oriented-
programming-concepts-in-C-Sharp/
References
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India
Questions?
http://www.ifourtechnolab.com/
ASP.NET Software Development Companies India