Data Types

Category: Entertainment

Presentation Description

No description available.


Presentation Transcript

Data Types:

Data Types In CSharp

Integers :

Integers Integers are whole numbers. There are two types that we will use to hold integers, byte and int. Variables of type byte can hold values from 0 to 255. Variables of type int can hold values from about minus two billion to plus two billion. Other integer types include short and long. // Declare a variable called number1 to hold a whole number int number1; // Declare a variable called smallNumber to hold a small whole number byte smallNumber smallNumber = 120;

Floats, Doubles & Decimals:

Floats, Doubles & Decimals C# also has a non-integer number type called float that has less precision than double. In fact, another name for non-integer numbers is floating point numbers, referring to the decimal point Numbers that are not whole numbers or that require extra precision can be represented by the double or decimal data types. The decimal type has greater precision, using 16 bytes of storage rather than the 8 bytes used for double. // Declare a variable called number1 to hold a double double number1; // Declare a variable called preciseMoney to hold a decimal decimal preciseMoney ; .

TEXT - Characters:

TEXT - Characters Characters To store a single character, be it a letter, a number, a symbol or a newline, we can use the char data type. Character literals are surrounded by single quotes. // Declare variables to hold characters char char1, char2, char3; char1 = 'b'; char2 = '6'; char3 = '\n'; Character Any letter, numeral or symbol in the given character set, such as the ASCII character set.

Strings :

Strings A sequence of zero or more characters is called a string. String literals are surrounded by double quotes. // Declare variables to hold strings string text1, text2, text3; text1 = ""; text2 = "b"; text3 = "Hello World!";

Dates and Times :

Dates and Times C# uses the DateTime data type to represent both dates and times. The DateTime class has methods and properties to help us work with dates and times. // Declare variables to hold Dates and Times DateTime today, tomorrow; today = DateTime.Today ; tomorrow = today.AddDays (1); DateTime dateFromString = System.Convert.ToDateTime ("5/12/2009");

Boolean Data :

Boolean Data Boolean variables can either be true or false . They are used in tests to control the flow of a program and to flag up certain states or conditions. In C# the bool data type is used to declare Boolean variables. // Declare variables to hold Boolean values bool test, condition, inPlay ; int health = 100; test = true; condition = false; inPlay = health > 0; // true

authorStream Live Help