2. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
1
3. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
2
Table of Contents
1.Design environment... 5
2.Visual Studio 2012 ..........................................................................................6
3.Character constants ...............................................................................................9
Example.......................................................................................................................9
4.Arithmetic Operators 10
Example.....................................................................................................................10
5.Variables 11
6.Code 12
6.Log in 13
7.Code 13
8.Code 16
9.Exercise 17
10.References (APA) 18
4. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
3
Table of Figure
Figure 1 -1 Visual Studio 2010..........................................................................................5
Figure 1 -2 New project..................................................................................................5
Figure 1 -3 windows from...............................................................................................6
Figure 1 -4 Toolbox........................................................................................................7
Figure 1 -5 properties ....................................................................................................8
Figure 0 -1 APPmVP6 ...................................................................................................12
Figure 0 -1 Log in.........................................................................................................13
Figure 0-1 New window...............................................................................................14
Figure 0 -2 window Name ............................................................................................15
Figure 0 -3 widow C# ..................................................................................................15
5. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
4
Design environment
Variables
Simple program of C#
Character constants
Arithmetic Operators
Exerciser
Define the Primitive Tool box and properties of visual studio.
list the types of data and how to use
list the types of Tool box and properties and how to use.
Create a micro program of C#.
Analysis the code of C#.
Objective of this chapter student will be able to:
Lesson Content:
6. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
5
1.Design environment
Start a subscription from Visual Studio 2012 or Visual Studio2010. Go to the File
menu and choose New Project
(Visual Studio2010)
This window will also allow you to change the name of the program and
Figure1-1Visual Studio 2010
Figure 1-2 New project
7. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
6
the path to save it, and then press OK
2.Visual Studio 2012
Figure 1-3 windows from
8. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
7
After pressing OK, the following window will appear for the first project
Window (1:)
The tools that include the Clear wares are called the two
programs
Figure 1-4 Toolbox
9. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
8
Window 2
Which will put in place the tools needed to build the project as well as
possible.
Figure 1-5 properties
10. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
9
3.Character constants
Character literals are included in single quotes. For example, 'x' can be
stored in a simple variable of char type. A literal character can be a
regular character (such as 'x'), an escape sequence (such as ' t'), or a
generic character (such as ' u02C0'). There are some characters in C #
when preceded by a backslash. They have a special meaning and are
used to represent such as the new font ( n) or the tab ( t). The
following is a list of some of these escape sequence codes:
Escape sequence Meaning
character
' ' character
" " character
? ? character
a Alert or bell
b Backspace
f Form feed
n Newline
r Carriage return
t Horizontal tab
Table 0-1 Character literals
// private void button1_Click(object sender, EventArgs e)
11. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
10
4.Arithmetic Operators
Following table shows all the arithmetic operators supported by C#.
Assume variable A holds 10 and variable B holds 20 then:
Operator Description Example
+ Adds two operands A + B = 30
- Subtracts second operand from the first A - B = -10
* Multiplies both operands A * B = 200
/ Divides numerator by de-numerator B / A = 2
% Modulus Operator and remainder of after an integer
division
B % A = 0
++ Increment operator increases integer value by one A++ = 11
-- Decrement operator decreases integer value by one A-- = 9
Table 0-1 Arithmetic Operators
Example
x = int.Parse(textBox1.Text);
y = int.Parse(textBox2.Text);
r = x * y;
textBox3.Text = r.ToString();
12. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
11
5.Variables
Program (1) A new project was established
File -> New -> Project
1- Button:
Name: button1 Text: ok
2- Button:
Name: button2 Text: Close
1- textBox1:
Name: Name. Text
2- textBox1:
Name: phone. Text
13. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
12
1- Label1:
For = Name
Name: Name. Text
Text: Name
2- Label2:
For = phone
Text: phone.
6.Code
Double-click on button ok Then write the code inside the button
Double-click on button Close Then write the code inside the button
MessageBox.Show(" Name =" + Name. Text + " phone =" + phone. Text);
Close ();
Figure 0-1 APPmVP6
14. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
13
6.Log in
1- Button:
Name: button1 Text: ok
2- Button:
Name: button2 Text:
Close
1- textBox1:
Name: User Name
2- textBox1:
Name: password
7.Code
Double-click on button ok Then write the code inside the button
Figure 0-1 Log in
if (textBox1.Text == "123" && textBox2.Text == "123")
{
window sig = new window();
sig.Show();
}
else
{
MessageBox.Show("Please Check your username or password");
15. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
14
Double-click on button Close Then write the code inside the button
Figure 0-1 New window
New window was created
windows forma Application > ADD> window form
Close ();
16. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
15
Window Name > ADD
*You can add any name
1- linkLabel1:
Name: C#
Link:
http://www.ttcollege.edu.sa/
-2 pictureBox1
Figure0-2 window Name
Figure 0-3 widow C#
17. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
16
8.Code
Double-click on linkLabel1 Then write the code inside the linkLabel1
System.Diagnostics.Process.Start("http://www.ttcollege.edu.sa/");
18. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
17
9.Exercise
1- Create a new project in visual studio and demonstrate the use of menu strips, menu bars,
context menus, and status bar.
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
2- Create a new project in visual studio and demonstrate the program
that collects two numbers.
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
19. Chapter 2Unit: 1 C# language componentsBasics of C# Programming
18
10.References (APA)
Hejlsberg, A., Torgersen, M., Wiltamuth, S., & Golde, P. (2010). C# Programming language.
Addison-Wesley Professional.
Obasanjo, D. (2002). A comparison of Microsoft’s C# programming language to Sun
Microsystem’s Java programming language.
Marshall, D. (2005). Programming Microsoft Visual C# 2005 Core Reference. Microsoft Press.