Software Development  Training Program KAZIM HUSSAIN
First C# Program <ul><li>using System; </li></ul><ul><li>public class First </li></ul><ul><li>{ </li></ul><ul><li>public s...
Parts of a C# Program <ul><li>Class Name </li></ul><ul><li>  public class First </li></ul><ul><li>Main method </li></ul><u...
Bits and Bytes <ul><li>Bit is the smallest unit of storage </li></ul><ul><li>Bit is a digit that can have only two values:...
Memory allocation 10011001 11111001 01110101 10010101 11000001 10111001 01001110 11000101 Main Memory                
Types of Data: “ Datatypes ” <ul><li>Data types are very important in every language for storing and manipulating data </l...
Datatypes and size in memory <ul><li>Integer Types </li></ul>C# Keyword Size bits/bytes Signed/ Unsigned Type in System Ra...
Datatypes and size in memory <ul><li>Floating-Point and Decimal Types </li></ul>C# Keyword Size bits/bytes Significant Fig...
Datatypes and size in memory <ul><li>Character Types </li></ul><ul><li>Boolean Types </li></ul>C# Keyword Size bits/bytes ...
Literals <ul><li>A value of any kind is called a literal </li></ul><ul><li>Integer literals </li></ul><ul><ul><ul><ul><li>...
Literals <ul><li>NOTE : </li></ul><ul><li>All the integer types are considered  int  or  long  type by default. </li></ul>...
Literals <ul><li>If you want to add two byte or short like: </li></ul><ul><li>byte a = 5; </li></ul><ul><li>byte b = 5; </...
Binary Representation <ul><li>Decimal Numbers </li></ul><ul><li>Binary numbers </li></ul><ul><li>Conversion of decimal num...
What is a Variable? <ul><li>`vary` -able   means  change- able </li></ul><ul><li>The variable is the basic unit of storage...
Example <ul><li>Some variable declarations examples: - </li></ul><ul><li>1. int a = 3; </li></ul><ul><li>2. int x,y,z; x =...
What is a Identifier? <ul><li>Identifiers are used to name variables, classes, interfaces, methods, and other elements.  <...
Rules for Identifiers <ul><li>A-Z, a-z, 0-9,_,@ </li></ul><ul><li>Must not start with digit </li></ul><ul><li>So following...
Invalid Identifiers <ul><li>Followings are invalid identifiers: - </li></ul><ul><li>&total </li></ul><ul><li>Minute# </li>...
Identifiers <ul><li>Both uppercase and lowercase letters can be used in an identifier. Because C# is case sensitive, there...
What is a Keyword? abstract default foreach null sealed uint as delegate goto object short ulong base do if operator sizeo...
Casting / Conversion <ul><li>Implicit casting </li></ul><ul><li>When one type of data is assigned to the other type of var...
Casting / Conversion <ul><li>byte a = 5; </li></ul><ul><li>int b = a; </li></ul><ul><li>long c = b; </li></ul><ul><li>doub...
Casting / Conversion <ul><li>Explicit casting </li></ul><ul><li>When you want to assign a larger value to a smaller value,...
Casting / Conversion <ul><li>NOTE : </li></ul><ul><li>When you explicitly cast large value to small value some information...
Upcoming SlideShare
Loading in …5
×

C Sharp Jn (1)

754 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
754
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • C Sharp Jn (1)

    1. 1. Software Development Training Program KAZIM HUSSAIN
    2. 2. First C# Program <ul><li>using System; </li></ul><ul><li>public class First </li></ul><ul><li>{ </li></ul><ul><li>public static void Main(string[] args) </li></ul><ul><li>{ </li></ul><ul><li>Console.WriteLine(“I belong to Operation Badar”); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
    3. 3. Parts of a C# Program <ul><li>Class Name </li></ul><ul><li> public class First </li></ul><ul><li>Main method </li></ul><ul><ul><li>public static void Main(string[] args) </li></ul></ul><ul><li>Statements </li></ul><ul><ul><li>Console.WriteLine(“I belong to Operation Badar”); </li></ul></ul>
    4. 4. Bits and Bytes <ul><li>Bit is the smallest unit of storage </li></ul><ul><li>Bit is a digit that can have only two values: ‘0’ or ‘1’ </li></ul><ul><li>A byte is made up of 8 “bits” </li></ul>1 Byte 8 Bits 1 0 0 1 1 1 0 1
    5. 5. Memory allocation 10011001 11111001 01110101 10010101 11000001 10111001 01001110 11000101 Main Memory                
    6. 6. Types of Data: “ Datatypes ” <ul><li>Data types are very important in every language for storing and manipulating data </li></ul><ul><li>Different kinds of data exist </li></ul><ul><li>All have different features hence difference requirements </li></ul><ul><li>Nature of data determines its “type” </li></ul>
    7. 7. Datatypes and size in memory <ul><li>Integer Types </li></ul>C# Keyword Size bits/bytes Signed/ Unsigned Type in System Range sbyte 8 bits / 1 byte signed SByte -128 to 127 byte 8 bits / 1 byte unsigned Byte 0 to 255 short 16 bits / 2 bytes signed Int16 -32765 to 32768 ushort 16 bits / 2 bytes unsigned UInt16 0 to 65535 int 32 bits / 4 bytes signed Int32 -2147483648 to 2147483647 uint 32 bits / 4 bytes unsigned UInt32 0 to 4294967195 long 64 bits / 8 bytes signed Int64 -9223373036854775808 to -9223373036854775807 ulong 64 bits / 8 bytes unsigned UInt64 0 to 18446744073709551615
    8. 8. Datatypes and size in memory <ul><li>Floating-Point and Decimal Types </li></ul>C# Keyword Size bits/bytes Significant Figures Type in System Range float 32 bits / 4 bytes 7 Single -3.40282347E38 to 3.40282347E38 1.5 * 10 -45 to 3.4 * 10 38 double 64 bits / 8 bytes 15 Double -1.7976931348623157E308 to 1.7976931348623157E308 5.0 * 10 -324 to 1.7 * 10 308 decimal 96 bits / 12 bytes 28 Decimal -79228162514264337593543950335 to 79228162514264337593543950335 1.0 * 10 -28 to 7.9 * 10 28
    9. 9. Datatypes and size in memory <ul><li>Character Types </li></ul><ul><li>Boolean Types </li></ul>C# Keyword Size bits/bytes Type in System Value bool 8 bits / 1 byte Boolean true and false C# Keyword Size bits/bytes Type in System Value char 16 bits / 2 bytes Char All Unicode Character
    10. 10. Literals <ul><li>A value of any kind is called a literal </li></ul><ul><li>Integer literals </li></ul><ul><ul><ul><ul><li>int count = 2250; / long = 7854214; </li></ul></ul></ul></ul><ul><li>Floating point literals </li></ul><ul><ul><ul><ul><li>double d=2.5 E-5.0; / decimal f = 34.34m; </li></ul></ul></ul></ul><ul><li>Character literals </li></ul><ul><ul><ul><li> char c=‘B’; </li></ul></ul></ul><ul><li>Boolean literals </li></ul><ul><ul><ul><li>bool b=false; // also ‘true’ </li></ul></ul></ul>
    11. 11. Literals <ul><li>NOTE : </li></ul><ul><li>All the integer types are considered int or long type by default. </li></ul><ul><li>All the floating point types are considered double by default. </li></ul><ul><li>So if you want to store 4.4 in float datatype you can not write this: - float f = 4.4; / decimal d = 4.4; </li></ul><ul><li>Instead you write float f = 4.4f; decimal d = 4.4m; </li></ul><ul><li>This way you explicitly tell the compiler to treat 4.4 as float. </li></ul>
    12. 12. Literals <ul><li>If you want to add two byte or short like: </li></ul><ul><li>byte a = 5; </li></ul><ul><li>byte b = 5; </li></ul><ul><li>byte c = a+b; </li></ul><ul><li>Instead you write </li></ul><ul><li>byte a = 5; </li></ul><ul><li>byte b = 5; </li></ul><ul><li>int c = a+b; </li></ul>
    13. 13. Binary Representation <ul><li>Decimal Numbers </li></ul><ul><li>Binary numbers </li></ul><ul><li>Conversion of decimal numbers into binary </li></ul><ul><li>Conversion of binary numbers into decimal numbers </li></ul>
    14. 14. What is a Variable? <ul><li>`vary` -able means change- able </li></ul><ul><li>The variable is the basic unit of storage. A variable is defined by the combination of a type, variable name and an optional initializer. In c# all variables must be declared before they can be used. int a = 4; </li></ul>Type Name Initial value
    15. 15. Example <ul><li>Some variable declarations examples: - </li></ul><ul><li>1. int a = 3; </li></ul><ul><li>2. int x,y,z; x = 4; y = 6; z = 3; </li></ul><ul><li>3. char c = ‘a’; </li></ul><ul><li>4. bool b = true; </li></ul><ul><li>5. double d = 44.4, v = 43.3; </li></ul>
    16. 16. What is a Identifier? <ul><li>Identifiers are used to name variables, classes, interfaces, methods, and other elements. </li></ul><ul><li>An identifier is a sequence of characters that starts with an underscore ( _ ), or a letter. Subsequent characters may contain these characters plus the digits 0 through 9. </li></ul>
    17. 17. Rules for Identifiers <ul><li>A-Z, a-z, 0-9,_,@ </li></ul><ul><li>Must not start with digit </li></ul><ul><li>So followings are valid identifiers: - </li></ul><ul><li>_minute </li></ul><ul><li>total </li></ul><ul><li>Sum4 </li></ul><ul><li>Hello67_hello </li></ul><ul><li>@abc_34 </li></ul><ul><li>_34343 </li></ul>
    18. 18. Invalid Identifiers <ul><li>Followings are invalid identifiers: - </li></ul><ul><li>&total </li></ul><ul><li>Minute# </li></ul><ul><li>4hour </li></ul><ul><li>@12hello </li></ul><ul><li>[email_address] </li></ul><ul><li>$asdfa </li></ul>
    19. 19. Identifiers <ul><li>Both uppercase and lowercase letters can be used in an identifier. Because C# is case sensitive, therefore these are treated as different identifiers: - </li></ul><ul><li>Total </li></ul><ul><li>total </li></ul><ul><li>TOTAL </li></ul><ul><li>toTal </li></ul>
    20. 20. What is a Keyword? abstract default foreach null sealed uint as delegate goto object short ulong base do if operator sizeof unchecked bool double implicit out stackalloc unsafe break else in override static ushort byte enum int params string using case event interface private struct virtual catch explicit internal protected switch void checked extern is public this while class false lock readonly throw const finally long ref true continue fixed namespace return try decimal float new sbyte typeof
    21. 21. Casting / Conversion <ul><li>Implicit casting </li></ul><ul><li>When one type of data is assigned to the other type of variable, an automatic type conversion occurs if left hand type is larger than the right hand type. This conversion is sometimes called widening conversion since you are converting small value to large value. </li></ul>
    22. 22. Casting / Conversion <ul><li>byte a = 5; </li></ul><ul><li>int b = a; </li></ul><ul><li>long c = b; </li></ul><ul><li>double d = c; </li></ul><ul><li>All the above are implicit type casting examples. The right hand side is smaller than the left hand side </li></ul>
    23. 23. Casting / Conversion <ul><li>Explicit casting </li></ul><ul><li>When you want to assign a larger value to a smaller value, you can not do it without explicitly casting it using the cast operator. This conversion is sometimes called narrowing conversion since you are explicitly making the value narrower to fit into the small size. </li></ul><ul><li> The syntax for explicit casting is: </li></ul><ul><li>target variable = (target) value; </li></ul>
    24. 24. Casting / Conversion <ul><li>NOTE : </li></ul><ul><li>When you explicitly cast large value to small value some information may be lost. For example, when floating point value is assigned to an integer the fractional part is lost </li></ul><ul><li>int a = 5; </li></ul><ul><li>byte b = a; </li></ul><ul><li>The second line will cause error. You can cast the second line like this using cast operator. </li></ul><ul><li>byte b = (byte) a; </li></ul>

    ×