0% found this document useful (0 votes)
4 views26 pages

Day 2

Uploaded by

Tanureet Kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views26 pages

Day 2

Uploaded by

Tanureet Kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 26

Er.

Roop Lal
Assistant Professor-CSE 3rd
Years.
Wipro Certificated.

1
C#
University of Virginia
 A data type specifies the type of
data that a variable can store
such as integer, floating,
character etc.

CSharp (© John Knight 2005) 2


C#
University of Virginia
CSharp (© John Knight 2005) 3
C#
University of Virginia
CSharp (© John Knight 2005) 4 University of Virginia
1. Value Data Type
The value data types are integer-based and
floating-point based. C# language supports
both signed and unsigned literals.
There are 2 types of value data type in C#
language.

CSharp (© John Knight 2005) 5


C#
University of Virginia
CSharp (© John Knight 2005) 6
C#
University of Virginia
CSharp (© John Knight 2005) 7
C#
University of Virginia
What is Parse() and Try Parse() in C#

CSharp (© John Knight 2005) 8


C#
University of Virginia
CSharp (© John Knight 2005) 9
C#
University of Virginia
CSharp (© John Knight 2005) 10
C#
University of Virginia
CSharp (© John Knight 2005) 11
C#
University of Virginia
12
C#
University of Virginia
13
C#
University of Virginia
14
C#
University of Virginia
15
C#
University of Virginia
•Q.1Write a program that takes a string input from the user and tries to
convert it to an integer using the int.Parse method.

•Q.2. Write a program that asks the user to enter a decimal number. If
the input is a valid double, print "Valid double: [value]". If not, print
"Invalid input".

Q.3. Write a program that asks the user to enter a boolean value (true or
false). If the input is a valid boolean, print "Valid boolean: [value]". If not,
print "Invalid input.

Q.4 Write a program that asks the user to enter a date and time. If the
input is a valid DateTime, print "Valid DateTime: [value]". If not, print
"Invalid input".

C#
University of Virginia
17
C#
University of Virginia
C#
University of Virginia18
C#
University of Virginia19
C#
University of Virginia20
C#
University of Virginia21
C#
University of Virginia22
C#
University of Virginia23
C#
University of Virginia24
C#
University of Virginia25
.

 Q.1Write a program that takes a user input string


and attempts to convert it to different data types
(int, double, DateTime, and bool). Print the
results of the conversions.
 Q.2 Write a program that demonstrates the use of
nullable types. Prompt the user to enter a number,
and allow for the possibility that the user might not
enter anything. Handle this case using a nullable int.
 Q.3 Write a program that asks the user to enter a
string representation of an integer, a double, and a
boolean. Use int.TryParse, double.TryParse, and
bool.TryParse to convert these strings to their
respective data types. Print the results if the
conversion is successful or an error message if it
fails.

26
C#
University of Virginia

You might also like