0% found this document useful (0 votes)
23 views

Data Type 2

The document discusses different data types in C# including their names, sizes, default values, and ranges. It provides examples of declaring variables of different types and performing operations on them. It also covers converting between data types, input and output commands, logical and comparison operators.

Uploaded by

mhammadnjmaden45
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Data Type 2

The document discusses different data types in C# including their names, sizes, default values, and ranges. It provides examples of declaring variables of different types and performing operations on them. It also covers converting between data types, input and output commands, logical and comparison operators.

Uploaded by

mhammadnjmaden45
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Visual Programming C#

DATA TYPES

Data types are sets (ranges) of values that have similar characteristics.
Characteristics : Data types are characterized by: -
- Name - for example, int x;
- Size - (how much memory they use) – for example, 4 bytes;
- Default value - for example 0.
Type Represents Range Default

bool Boolean value True or False


byte 8-bit unsigned integer 0 to 255
Int 32-bit signed integer type -2,147,483,648 to 2,147,483,647
float 32-bit single-precision floating point -3.4 x 1038 to + 3.4 x 1038
type
double 64-bit double-precision floating (+/-)5.0 x 10-324 to (+/-)1.7 x 10308
point type
char 16-bit Unicode character U +0000 to U +ffff
String String values 1 bit for each letter
2
• Char type use ‘ ‘ single quote while String use double quotes “ “.
• Examples:
(1)
Int x , y , r;
x = 5; y = 4;
r = x + y;
Console.WriteLine(“ The sum result is : ” + r) ;

(2)
Char let1 = ‘ A ‘ , let2= ‘ l ‘, let3 = ‘ i ‘ ;
Console.WriteLine(“The name is : ” + let1 + let2 + let3);

(3)
String str1 = “Azhen”, str2=“Ahmed”;
Console.WriteLine( str1 + “ “ + str2 );

3
Write: Is a print command print data in a same line.
WriteLine: Is a print command print data and take the pointer to the new
line.
ReadLine: Is an input command used to input data.
Ex4:
Console.Write("Write your name : ");
String a = Console.ReadLine();
Console.WriteLine("The Input is : " + a );
-----------------------------------------------------------------------------
• The example above is to read, input string type and print string type.
• All the input data inside the “ ReadLine (); ” are string type.
• We should convert the data type if we want to read or input a number
type.

4
Convert Among the data types
EX5:
Console.Write("Enter the first number : ");
String strnumber1 = Console.ReadLine();
Console.Write("Enter the Second number : ");
String strnumber2 = Console.ReadLine();
int num1 = int.Parse(strnumber1);
int num2 = int.Parse(strnumber2);
int r= num1 + num2;
Console.WriteLine("The sum is : " + r);
==============================================
Int.Parse (); used when we want to convert string to the integer.
The Console is a window of the operating system through which users can
interact with system programs of the operating system or with other console
applications.

5
EX6:
// Convert from integer to string.
int number1 = 97;
int number2 = 3;
string r;
r = Convert.ToString(number1) + number2;
Console.WriteLine(r);
==============================
The result above will be 973 because it’s a string type not integer type.
Convert.ToSrting (); used when we want to convert to string type.
==============================

Const double pi=3.14; // Const command used to defined a constant.

6
Operators: Every programming language uses operators, through which we
can perform different actions on the data.

7
Logical Operators – Example

bool T = true;
bool F = false;
Console.WriteLine(T && F); // False
Console.WriteLine(T || F); // True
Console.WriteLine(!F); // True
Console.WriteLine(F || true); // True

8
Comparison Operators:

Comparison operators can be used to compare expressions such as two


numbers, two numerical expressions, or a number and a variable. The result
of the comparison is a Boolean value (true or false).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy