SlideShare a Scribd company logo
Write and WriteLine Methods
// Namespace Declaration
using System;
// Program start class
class InteractiveWelcome
{
// Main begins program execution.
public static void Main()
{
// Write to console/get input
Console.Write("What is your name?: ");
Console.Write("Hello, {0}! ", Console.ReadLine());
Console.WriteLine("Welcome to the C# Station Tutorial!");
}
}
Output:
>What is your Name? <type your name here> [Enter Key]
>Hello, <your name here>! Welcome to the C# Station Tutorial!
Read and ReadLine Methods
User input from the keyboard by using the Console.Read and
Console.ReadLine methods.
The Read Method
Read reads the next character from the keyboard. It returns the int
value –1 if there is no more input available. Otherwise it returns an
int representing the character read.
The ReadLine Method
ReadLine reads all characters up to the end of the input line (the
carriage return character). The input is returned as a string of
characters. You can use the following code to read a line of text from
the keyboard and display it to the screen:
string input = Console.ReadLine( );
Console.WriteLine(“{0}”, input);
The following codeshows some examples of how to use numeric formatting:
Console.WriteLine(“Currency formatting – {0:C} {1:C4}”, 88.8,-888.8);
Console.WriteLine(“Integer formatting – {0:D5}”, 88);
Console.WriteLine(“Exponential formatting – {0:E}”, 888.8);
Console.WriteLine(“Fixed-point formatting – {0:F3}”,888.8888);
Console.WriteLine(“General formatting – {0:G}”, 888.8888);
Console.WriteLine(“Number formatting – {0:N}”, 8888888.8);
Console.WriteLine(“Hexadecimal formatting – {0:X4}”, 88);
When the previous code is run, it displays the following:
Currency formatting – $88.80 ($888.8000)
Integer formatting – 00088
Exponential formatting – 8.888000E+002
Fixed-point formatting – 888.889
General formatting – 888.8888
Number formatting – 8,888,888.80
Hexadecimal formatting – 0058
BOOLEAN DATA TYPE
using System;
class BooleanType
{
static void Main()
{
bool male = false;
Random random = new Random();
male = Convert.ToBoolean(random.Next(0, 2));
if (male)
{
Console.WriteLine("We will use name John");
} else
{
Console.WriteLine("We will use name Victoria");
}
}
}
VB Alias .NET Type Size Range
sbyte System.SByte 1 byte -128 to 127
byte System.Byte 1 byte 0 to 255
short System.Int16 2 bytes -32,768 to 32,767
ushort System.UInt16 2 bytes 0 to 65,535
int System.Int32 4 bytes -2,147,483,648 to 2,147,483,647
uint System.UInt32 4 bytes 0 to 4,294,967,295
long System.Int64 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
ulong System.UInt64 8 bytes 0 to 18,446,744,073,709,551,615
using System;
class Overflow
{
static void Main()
{
byte a = 254;
Console.WriteLine(a);
a++;
Console.WriteLine(a);
a++;
Console.WriteLine(a);
a++;
Console.WriteLine(a);
}
}
Output:
254
255
0
1
using System;
class Notations
{
static void Main()
{
int num1 = 31;
int num2 = 0x31;
Console.WriteLine(num1);
Console.WriteLine(num2);
}
}
Output:
31
49
using System;
public class Apples
{
static void Main()
{
int baskets = 16;
int applesInBasket = 24;
int total = baskets * applesInBasket;
Console.WriteLine("There are total of {0} apples", total);
}
}
Output:
There are total of 384 apples
C#
Alias
.NET Type Size Precision Range
Float System.Single
4
bytes
7 digits
1.5 x 10-45 to
3.4 x 1038
Double System.Double
8
bytes
15-16 digits
5.0 x 10-324 to
1.7 x 10308
decimal System.Decimal
16
bytes
28-29 decimal
places
1.0
using System;
class Floats
{
static void Main()
{
float n1 = 1.234f;
double n2 = 1.234;
decimal n3 = 1.234m;
Console.WriteLine(n1);
Console.WriteLine(n2);
Console.WriteLine(n3);
Console.WriteLine(n1.GetType());
Console.WriteLine(n2.GetType());
Console.WriteLine(n3.GetType());
}
}
To use a different type, we must use a suffix.
The F/f for float numbers and M/m for decimal numbers.
using System;
class Notations
{
static void Main()
{
float n1 = 1.234f;
float n2 = 1.2e-3f;
float n3 = (float) 1 / 3;
Console.WriteLine(n1);
Console.WriteLine(n2);
Console.WriteLine(n3);
}
}
Output:
1.234
0.0012
0.3333333
using System;
class CSharpApp
{
static void Main()
{
float n1 = (float) 1 / 3;
double n2 = (double) 1 / 3;
if (n1 == n2)
{
Console.WriteLine("Numbers are equal");
} else {
Console.WriteLine("Numbers are not equal");
}
}
}
Output:
Numbers are not equal
Enumerations
using System;
class Enumerations
{
enum Days
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}
static void Main()
{
Days day = Days.Monday;
if (day == Days.Monday)
{
Console.WriteLine("It is Monday");
}
Console.WriteLine(day);
foreach(int i in Enum.GetValues(typeof(Days)))
Console.WriteLine(i);
}
}
ARRAYS
using System;
class ArrayExample
{
static void Main()
{
int[] numbers = new int[5];
numbers[0] = 3;
numbers[1] = 2;
numbers[2] = 1;
numbers[3] = 5;
numbers[4] = 6;
int len = numbers.Length;
for (int i=0; i<len; i++)
{
Console.WriteLine(numbers[i]);
}
}
}

More Related Content

What's hot

15. text files
15. text files15. text files
15. text files
Konstantin Potemichev
 
Learn Java Part 4
Learn Java Part 4Learn Java Part 4
Learn Java Part 4
Gurpreet singh
 
Stream
StreamStream
21csharp
21csharp21csharp
21csharp
Sireesh K
 
Java 1
Java 1Java 1
Dr. Rajeshree Khande - Java Interactive input
Dr. Rajeshree Khande - Java Interactive inputDr. Rajeshree Khande - Java Interactive input
Dr. Rajeshree Khande - Java Interactive input
jalinder123
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
Rakesh Madugula
 
Networking
NetworkingNetworking
Networking
Jafar Nesargi
 
Classes of ip addresses
Classes of ip addressesClasses of ip addresses
Classes of ip addresses
NetProtocol Xpert
 
Inputstream
InputstreamInputstream
Inputstream
Rajasekhar Reddy
 

What's hot (10)

15. text files
15. text files15. text files
15. text files
 
Learn Java Part 4
Learn Java Part 4Learn Java Part 4
Learn Java Part 4
 
Stream
StreamStream
Stream
 
21csharp
21csharp21csharp
21csharp
 
Java 1
Java 1Java 1
Java 1
 
Dr. Rajeshree Khande - Java Interactive input
Dr. Rajeshree Khande - Java Interactive inputDr. Rajeshree Khande - Java Interactive input
Dr. Rajeshree Khande - Java Interactive input
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Networking
NetworkingNetworking
Networking
 
Classes of ip addresses
Classes of ip addressesClasses of ip addresses
Classes of ip addresses
 
Inputstream
InputstreamInputstream
Inputstream
 

Similar to Write and write line methods

C#.net
C#.netC#.net
C#.net
vnboghani
 
04. Console Input Output
04. Console Input Output 04. Console Input Output
04. Console Input Output
Intro C# Book
 
basic c++(1)
basic c++(1)basic c++(1)
basic c++(1)
sajidpk92
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
sajidpk92
 
c++ Lecture 1
c++ Lecture 1c++ Lecture 1
c++ Lecture 1
sajidpk92
 
04 Console input output-
04 Console input output-04 Console input output-
04 Console input output-
maznabili
 
434090527-C-Cheat-Sheet. pdf C# program
434090527-C-Cheat-Sheet. pdf  C# program434090527-C-Cheat-Sheet. pdf  C# program
434090527-C-Cheat-Sheet. pdf C# program
MAHESHV559910
 
C# basics
 C# basics C# basics
C# basics
Dinesh kumar
 
C#
C#C#
Basics1
Basics1Basics1
Basics1
phanleson
 
C# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdfC# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdf
ssuserc77a341
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
SURBHI SAROHA
 
Csphtp1 03
Csphtp1 03Csphtp1 03
Csphtp1 03
HUST
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
UNIVERSITY OF ENGINEERING AND TECHNOLOGY TAXILA
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
Marco Izzotti
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
Anonymous9etQKwW
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdf
ssusera0bb35
 
Cordovilla
CordovillaCordovilla
Cordovilla
brianmae002
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
ExcellenceAcadmy
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
ExcellenceAcadmy
 

Similar to Write and write line methods (20)

C#.net
C#.netC#.net
C#.net
 
04. Console Input Output
04. Console Input Output 04. Console Input Output
04. Console Input Output
 
basic c++(1)
basic c++(1)basic c++(1)
basic c++(1)
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
c++ Lecture 1
c++ Lecture 1c++ Lecture 1
c++ Lecture 1
 
04 Console input output-
04 Console input output-04 Console input output-
04 Console input output-
 
434090527-C-Cheat-Sheet. pdf C# program
434090527-C-Cheat-Sheet. pdf  C# program434090527-C-Cheat-Sheet. pdf  C# program
434090527-C-Cheat-Sheet. pdf C# program
 
C# basics
 C# basics C# basics
C# basics
 
C#
C#C#
C#
 
Basics1
Basics1Basics1
Basics1
 
C# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdfC# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdf
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
 
Csphtp1 03
Csphtp1 03Csphtp1 03
Csphtp1 03
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdf
 
Cordovilla
CordovillaCordovilla
Cordovilla
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
 

More from Dr.M.Karthika parthasarathy

IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
Dr.M.Karthika parthasarathy
 
Linux Lab Manual.doc
Linux Lab Manual.docLinux Lab Manual.doc
Linux Lab Manual.doc
Dr.M.Karthika parthasarathy
 
Unit 2 IoT.pdf
Unit 2 IoT.pdfUnit 2 IoT.pdf
Unit 3 IOT.docx
Unit 3 IOT.docxUnit 3 IOT.docx
Unit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxUnit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptx
Dr.M.Karthika parthasarathy
 
Unit I What is Artificial Intelligence.docx
Unit I What is Artificial Intelligence.docxUnit I What is Artificial Intelligence.docx
Unit I What is Artificial Intelligence.docx
Dr.M.Karthika parthasarathy
 
Introduction to IoT - Unit II.pptx
Introduction to IoT - Unit II.pptxIntroduction to IoT - Unit II.pptx
Introduction to IoT - Unit II.pptx
Dr.M.Karthika parthasarathy
 
IoT Unit 2.pdf
IoT Unit 2.pdfIoT Unit 2.pdf
Chapter 3 heuristic search techniques
Chapter 3 heuristic search techniquesChapter 3 heuristic search techniques
Chapter 3 heuristic search techniques
Dr.M.Karthika parthasarathy
 
Ai mcq chapter 2
Ai mcq chapter 2Ai mcq chapter 2
Ai mcq chapter 2
Dr.M.Karthika parthasarathy
 
Introduction to IoT unit II
Introduction to IoT  unit IIIntroduction to IoT  unit II
Introduction to IoT unit II
Dr.M.Karthika parthasarathy
 
Introduction to IoT - Unit I
Introduction to IoT - Unit IIntroduction to IoT - Unit I
Introduction to IoT - Unit I
Dr.M.Karthika parthasarathy
 
Internet of things Unit 1 one word
Internet of things Unit 1 one wordInternet of things Unit 1 one word
Internet of things Unit 1 one word
Dr.M.Karthika parthasarathy
 
Unit 1 q&amp;a
Unit  1 q&amp;aUnit  1 q&amp;a
Overview of Deadlock unit 3 part 1
Overview of Deadlock unit 3 part 1Overview of Deadlock unit 3 part 1
Overview of Deadlock unit 3 part 1
Dr.M.Karthika parthasarathy
 
Examples in OS synchronization for UG
Examples in OS synchronization for UG Examples in OS synchronization for UG
Examples in OS synchronization for UG
Dr.M.Karthika parthasarathy
 
Process Synchronization - Monitors
Process Synchronization - MonitorsProcess Synchronization - Monitors
Process Synchronization - Monitors
Dr.M.Karthika parthasarathy
 
.net progrmming part4
.net progrmming part4.net progrmming part4
.net progrmming part4
Dr.M.Karthika parthasarathy
 
.net progrmming part3
.net progrmming part3.net progrmming part3
.net progrmming part3
Dr.M.Karthika parthasarathy
 
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
Dr.M.Karthika parthasarathy
 

More from Dr.M.Karthika parthasarathy (20)

IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
 
Linux Lab Manual.doc
Linux Lab Manual.docLinux Lab Manual.doc
Linux Lab Manual.doc
 
Unit 2 IoT.pdf
Unit 2 IoT.pdfUnit 2 IoT.pdf
Unit 2 IoT.pdf
 
Unit 3 IOT.docx
Unit 3 IOT.docxUnit 3 IOT.docx
Unit 3 IOT.docx
 
Unit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxUnit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptx
 
Unit I What is Artificial Intelligence.docx
Unit I What is Artificial Intelligence.docxUnit I What is Artificial Intelligence.docx
Unit I What is Artificial Intelligence.docx
 
Introduction to IoT - Unit II.pptx
Introduction to IoT - Unit II.pptxIntroduction to IoT - Unit II.pptx
Introduction to IoT - Unit II.pptx
 
IoT Unit 2.pdf
IoT Unit 2.pdfIoT Unit 2.pdf
IoT Unit 2.pdf
 
Chapter 3 heuristic search techniques
Chapter 3 heuristic search techniquesChapter 3 heuristic search techniques
Chapter 3 heuristic search techniques
 
Ai mcq chapter 2
Ai mcq chapter 2Ai mcq chapter 2
Ai mcq chapter 2
 
Introduction to IoT unit II
Introduction to IoT  unit IIIntroduction to IoT  unit II
Introduction to IoT unit II
 
Introduction to IoT - Unit I
Introduction to IoT - Unit IIntroduction to IoT - Unit I
Introduction to IoT - Unit I
 
Internet of things Unit 1 one word
Internet of things Unit 1 one wordInternet of things Unit 1 one word
Internet of things Unit 1 one word
 
Unit 1 q&amp;a
Unit  1 q&amp;aUnit  1 q&amp;a
Unit 1 q&amp;a
 
Overview of Deadlock unit 3 part 1
Overview of Deadlock unit 3 part 1Overview of Deadlock unit 3 part 1
Overview of Deadlock unit 3 part 1
 
Examples in OS synchronization for UG
Examples in OS synchronization for UG Examples in OS synchronization for UG
Examples in OS synchronization for UG
 
Process Synchronization - Monitors
Process Synchronization - MonitorsProcess Synchronization - Monitors
Process Synchronization - Monitors
 
.net progrmming part4
.net progrmming part4.net progrmming part4
.net progrmming part4
 
.net progrmming part3
.net progrmming part3.net progrmming part3
.net progrmming part3
 
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
 

Recently uploaded

Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
Amin Marwan
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
Chevonnese Chevers Whyte, MBA, B.Sc.
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Leena Ghag-Sakpal
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 

Write and write line methods

  • 1. Write and WriteLine Methods // Namespace Declaration using System; // Program start class class InteractiveWelcome { // Main begins program execution. public static void Main() { // Write to console/get input Console.Write("What is your name?: "); Console.Write("Hello, {0}! ", Console.ReadLine()); Console.WriteLine("Welcome to the C# Station Tutorial!"); } } Output: >What is your Name? <type your name here> [Enter Key] >Hello, <your name here>! Welcome to the C# Station Tutorial!
  • 2. Read and ReadLine Methods User input from the keyboard by using the Console.Read and Console.ReadLine methods. The Read Method Read reads the next character from the keyboard. It returns the int value –1 if there is no more input available. Otherwise it returns an int representing the character read. The ReadLine Method ReadLine reads all characters up to the end of the input line (the carriage return character). The input is returned as a string of characters. You can use the following code to read a line of text from the keyboard and display it to the screen: string input = Console.ReadLine( ); Console.WriteLine(“{0}”, input);
  • 3. The following codeshows some examples of how to use numeric formatting: Console.WriteLine(“Currency formatting – {0:C} {1:C4}”, 88.8,-888.8); Console.WriteLine(“Integer formatting – {0:D5}”, 88); Console.WriteLine(“Exponential formatting – {0:E}”, 888.8); Console.WriteLine(“Fixed-point formatting – {0:F3}”,888.8888); Console.WriteLine(“General formatting – {0:G}”, 888.8888); Console.WriteLine(“Number formatting – {0:N}”, 8888888.8); Console.WriteLine(“Hexadecimal formatting – {0:X4}”, 88);
  • 4. When the previous code is run, it displays the following: Currency formatting – $88.80 ($888.8000) Integer formatting – 00088 Exponential formatting – 8.888000E+002 Fixed-point formatting – 888.889 General formatting – 888.8888 Number formatting – 8,888,888.80 Hexadecimal formatting – 0058
  • 5. BOOLEAN DATA TYPE using System; class BooleanType { static void Main() { bool male = false; Random random = new Random(); male = Convert.ToBoolean(random.Next(0, 2)); if (male) { Console.WriteLine("We will use name John"); } else { Console.WriteLine("We will use name Victoria"); } } }
  • 6. VB Alias .NET Type Size Range sbyte System.SByte 1 byte -128 to 127 byte System.Byte 1 byte 0 to 255 short System.Int16 2 bytes -32,768 to 32,767 ushort System.UInt16 2 bytes 0 to 65,535 int System.Int32 4 bytes -2,147,483,648 to 2,147,483,647 uint System.UInt32 4 bytes 0 to 4,294,967,295 long System.Int64 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 ulong System.UInt64 8 bytes 0 to 18,446,744,073,709,551,615
  • 7. using System; class Overflow { static void Main() { byte a = 254; Console.WriteLine(a); a++; Console.WriteLine(a); a++; Console.WriteLine(a); a++; Console.WriteLine(a); } } Output: 254 255 0 1
  • 8. using System; class Notations { static void Main() { int num1 = 31; int num2 = 0x31; Console.WriteLine(num1); Console.WriteLine(num2); } } Output: 31 49
  • 9. using System; public class Apples { static void Main() { int baskets = 16; int applesInBasket = 24; int total = baskets * applesInBasket; Console.WriteLine("There are total of {0} apples", total); } } Output: There are total of 384 apples
  • 10. C# Alias .NET Type Size Precision Range Float System.Single 4 bytes 7 digits 1.5 x 10-45 to 3.4 x 1038 Double System.Double 8 bytes 15-16 digits 5.0 x 10-324 to 1.7 x 10308 decimal System.Decimal 16 bytes 28-29 decimal places 1.0
  • 11. using System; class Floats { static void Main() { float n1 = 1.234f; double n2 = 1.234; decimal n3 = 1.234m; Console.WriteLine(n1); Console.WriteLine(n2); Console.WriteLine(n3); Console.WriteLine(n1.GetType()); Console.WriteLine(n2.GetType()); Console.WriteLine(n3.GetType()); } } To use a different type, we must use a suffix. The F/f for float numbers and M/m for decimal numbers.
  • 12. using System; class Notations { static void Main() { float n1 = 1.234f; float n2 = 1.2e-3f; float n3 = (float) 1 / 3; Console.WriteLine(n1); Console.WriteLine(n2); Console.WriteLine(n3); } } Output: 1.234 0.0012 0.3333333
  • 13. using System; class CSharpApp { static void Main() { float n1 = (float) 1 / 3; double n2 = (double) 1 / 3; if (n1 == n2) { Console.WriteLine("Numbers are equal"); } else { Console.WriteLine("Numbers are not equal"); } } } Output: Numbers are not equal
  • 14. Enumerations using System; class Enumerations { enum Days { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
  • 15. Sunday } static void Main() { Days day = Days.Monday; if (day == Days.Monday) { Console.WriteLine("It is Monday"); } Console.WriteLine(day); foreach(int i in Enum.GetValues(typeof(Days))) Console.WriteLine(i); } }
  • 16. ARRAYS using System; class ArrayExample { static void Main() { int[] numbers = new int[5]; numbers[0] = 3; numbers[1] = 2; numbers[2] = 1; numbers[3] = 5; numbers[4] = 6; int len = numbers.Length; for (int i=0; i<len; i++) {