1 / 17

Working with Variables, Operators and Expressions

Working with Variables, Operators and Expressions. 1. 2. 3. Statements -Comments. Identifiers. Variables. 4. 5. Primitive Data Types. Arithmetic Operators. 6. 7. Implicitly Typed Local Variables. Incrementing & Decrementing Variables.

alcina
Download Presentation

Working with Variables, Operators and Expressions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Working with Variables, Operators and Expressions

  2. 1 2 3 Statements -Comments Identifiers Variables 4 5 Primitive Data Types Arithmetic Operators 6 7 Implicitly Typed Local Variables Incrementing & Decrementing Variables

  3. -A Statement is a command that performs an action, you must add “;” the end of command -Ex: Console.Write(“Hello C# ”); 1 Statements -Comments -Comments use to explain for your Coding How to write comments??? See next slide…

  4. //Comment 1 /* *Comment 2 */ /*Comment 3*/ /// <summary> ///Write Comment 4 /// </summary> /// <paramname=“a"></param> /// <paramname=“b"></param> private void func1(inta,float b)

  5. Identifiers are names use to identify the elements in program, ex: namespace, class, method… Syntax Rules: -Only use letter, digit, underscore -An identifier must start with a letter or an underscore -C# is a case –sensitive : nTestand ntestis different identifier 2 Identifiers

  6. Identifying Keywords abstract do in protected true as double int public try base else interface readonlytypeof bool enum internal ref uint break event is return ulong byte explicit lock sbyte unchecked case extern long sealed unsafe catch false namespace short ushort char finally new sizeof using checked fixed null stackalloc virtual class float object static void const for operator string volatile continue foreach out struct while decimal goto override switch default if params this delegate implicit private throw dynamic join set from let value get orderbyvar group partial where into select yield

  7. - A variable is storage location that holds a value. It as a box in the Computer’s memory holding temporary information. -To easy coding: +Don’t start an identifier with underscore +Don’t different only by case ( nTestand ntest) +Start name with lower case +…. 3 Variables

  8. How to declare variables? Data_typeNameVariable; intnNumberOfElement; string strFullName; float fValue=0,fResult;

  9. 4 Primitive Data Types

  10. You should initialize value for variable intnSize=0; String strName=“”;

  11. + - * 5 / % Arithmetic Operators () intnPlusTwoNumber=113 + 114 The + is the operator 113 and 114 are the operands

  12. Not all operators are applicable to all data types Example: You will get compiler error with the statements: Console.WriteLine(“Tý” - “Tèo”);

  13. How to convert from String to Number Format ? intnValue=System.Int32.Parse("113"); doubledValue = System.Double.Parse("3.5"); DatatypevName=System.DataTypeObject.Parse(“string”);

  14. ++X Prefix increment X++ Postfix increment 6 Incrementing & Decrementing Variables X-- Postfix decrement --X Prefix decrement

  15. 7 varnumber1=1; varstrAny=“tèo”; Implicitly Typed Local Variables varsAny; Error: Implicitly-typed local variables must be initialized

  16. END

More Related