3C#-Numeric String and Data

download 3C#-Numeric String and Data

of 19

Transcript of 3C#-Numeric String and Data

  • 8/12/2019 3C#-Numeric String and Data

    1/19

    Numeric String and Data

  • 8/12/2019 3C#-Numeric String and Data

    2/19

    Built-in Value Types

  • 8/12/2019 3C#-Numeric String and Data

    3/19

    Declare and Initialize Variables

    A variable stores a value that can change as theprogram executes

    Declare and initialize a variable in one statement or

    assign a value immediately after you declare it Use camel notation as programming convention

    Example: type variableName;

    variableName=value;

  • 8/12/2019 3C#-Numeric String and Data

    4/19

    Declare and Initialize Constants

    A constant stores a value that cant be changed as theprogram executes

    Example:

    const type ConstantName=value;

  • 8/12/2019 3C#-Numeric String and Data

    5/19

    Naming Conventions

    Start the names of variables with a lowercase letter ,and capitalize the first letter of each word after first

    word, also called Camel Notation

    Capitalize the first letter of each word of a constantname, also called Pascal Notation

  • 8/12/2019 3C#-Numeric String and Data

    6/19

    Arithmetic Expressions

  • 8/12/2019 3C#-Numeric String and Data

    7/19

    Arithmetic Expression

    An arithmetic expression consists of one or moreoperands and arithmetic operators

    The first five binary operators above are called

    binary operators because they operate on twooperands . The next four are called unary operatorsbecause they operate because they operate on justone operand

  • 8/12/2019 3C#-Numeric String and Data

    8/19

    Assignment Operators

  • 8/12/2019 3C#-Numeric String and Data

    9/19

    Order of Precedence

    1. Increment and decrement

    2. Positive and negative

    3. Multiplication, division , and modulus

    4. Addition and subtraction

  • 8/12/2019 3C#-Numeric String and Data

    10/19

    Math Class

    Round method:

    Math.Round (decimalNumber[,precision])

    Pow method

    Math.Pow(number, power) Sqrt method Math.Sqrt(number)

    Min and Max methods Math.{Min/Max}(number1,number2)

  • 8/12/2019 3C#-Numeric String and Data

    11/19

    Strings

    A string can consist of any character includingsymbols

    String literal-value of string in closed quotes

    Null value-value of string is unknown Empty string-string with no value inside closed

    quotes

    Concatenation-join strings, uses the + sign

    Append-adding one string to another, += string isused

  • 8/12/2019 3C#-Numeric String and Data

    12/19

    Escape sequences

    \n new line

    \t tab

    \r carriage return

    \\ - backlash \ - quotation

  • 8/12/2019 3C#-Numeric String and Data

    13/19

    .NET structures and data types

  • 8/12/2019 3C#-Numeric String and Data

    14/19

    .NET structures and data types

    Each built in data type is supported by a structure ora class within the .NET framework. When you use aC# keyword to refer to a data type , youre actuallyusing an alias associated structure or class

    A structure define a value type which stores its owndata

    A class defines a reference type. A referenced typedoesnt store and data itself. Instead, it stores a

    reference to the area of memory where data is stored All structures and classes shown are in the System

    namespace

  • 8/12/2019 3C#-Numeric String and Data

    15/19

    Common methods for data conversion

  • 8/12/2019 3C#-Numeric String and Data

    16/19

    Some of the static methods of the convert class

  • 8/12/2019 3C#-Numeric String and Data

    17/19

    Standard numeric formatting codes

  • 8/12/2019 3C#-Numeric String and Data

    18/19

    How to use the ToString method to format a number

    H h F h d f h S i l

  • 8/12/2019 3C#-Numeric String and Data

    19/19

    How to use the Format method of the String classto format a number