1. DATA STRUCTURE
Chapter 1: Intro To Principle of
C#
Prepared & Presented by
Mr. Mahmoud R. Alfarra
2010-2011
College of Science & Technology
Dep. Of Computer Science & IT
BCs of Information Technology
http://mfarra.cst.ps
2. Out Line
What is C#?
Data types, declaration of variables
Calculations and logical operations
Control statements
Arrays
Methods
Class & Objects
2
البيانات تراكيب مساق
إعداد العلمية المادة
/
أ
.
ا َّالفــر رفيق محمود
3. What is C#?
C# (pronounced "C-sharp") is an object-
oriented programming language from Microsoft
that aims to combine the computing power of
C++ with the programming ease of Visual
Basic.
C# is based on C++ and contains features
similar to those of Java.
C# is designed to work with Microsoft's .Net
platform.
3
4. Applications of C#
Console Applications
Windows Applications
Mobile Applications
ASP .NET Web Applications
4
البيانات تراكيب مساق
إعداد العلمية المادة
/
أ
.
ا َّالفــر رفيق محمود
5. Data types, declaration of variables
5
البيانات تراكيب مساق
إعداد العلمية المادة
/
أ
.
ا َّالفــر رفيق محمود
Rules of variables in C# are the same of Java:
int x = 5, y = 9;
int x = 5;
int y = 9;
8. Selection statements
8
البيانات تراكيب مساق
إعداد العلمية المادة
/
أ
.
ا َّالفــر رفيق محمود
Selection statements in C# are identical with
java:
If
If … else
nested if
Switch
9. Example: Selection statements
9
using System;
1
class Marks_using_if_else
2
{
3
static void Main()
4
{
5
int mark;
6
String input;
7
Console.Write("Enter the mark: ");
8
//Read mark
9
input = Console.ReadLine();
10
mark = int.Parse(input);
11
//check the mark
12
if (mark >= 50)
13
Console.WriteLine("Passed");
14
Else
15
Console.WriteLine("Failed");
16
} }
17
10. Example: Selection statements
10
static void Main()
1
{
2
int mark;
3
string input;
4
Console.Write("Enter the mark: ");
5
//Read mark
6
input = Console.ReadLine();
7
mark = int.Parse(input);
8
//check the mark
9
if (mark >= 85)
10
Console.WriteLine("Excellent");
11
else if (mark >= 75)
12
Console.WriteLine("Very Good");
13
else if (mark >= 65)
14
Console.WriteLine("Good");
15
else if (mark >= 50)
16
Console.WriteLine("Passed");
17
Else
18
Console.WriteLine("Failed");
19
} }
20
11. Iteration statements
11
البيانات تراكيب مساق
إعداد العلمية المادة
/
أ
.
ا َّالفــر رفيق محمود
Iteration statements in C# like them of java
while
do… while
for
For each
12. Example: Iteration statements
12
البيانات تراكيب مساق
إعداد العلمية المادة
/
أ
.
ا َّالفــر رفيق محمود
static void Main(string[] args)
{
int fact = 1;
for (int i = 1; i <= 10; i++)
fact = fact * i;
Console.WriteLine("fact of 10 is" + fact);
Console.Read();
}
14. Arrays
14
البيانات تراكيب مساق
إعداد العلمية المادة
/
أ
.
ا َّالفــر رفيق محمود
type[] array_name = new type[ x ];
Type of elements No. of elements
type [] array_name;
array_name = new type[ x ];
1- D Array
15. Arrays
15
البيانات تراكيب مساق
إعداد العلمية المادة
/
أ
.
ا َّالفــر رفيق محمود
type[] [] array_name = new type[ x ][ y ];
Type of elemnts No. of rows
type [][] array_name;
array_name = new type[ x ][ y ];
No. of Col.
2- D array
16. Methods
16
البيانات تراكيب مساق
إعداد العلمية المادة
/
أ
.
ا َّالفــر رفيق محمود
return_type function_name (parameters type para_name)
{
// statements
Return_type;
}
Variable of returned type Name of method Parameters
17. Method’s call
17
البيانات تراكيب مساق
إعداد العلمية المادة
/
أ
.
ا َّالفــر رفيق محمود
To call (invoke) method sum, which receives two
integers numbers, and return their sum, we write the
following code:
int x = sum (4,5);
To download more example and practices
about
the principles of c#, please visit my site
and you tube channel:
http://mfarra.cst.ps
www.youtube.com/mralfarra1
18. Thank You …
18
البيانات تراكيب مساق
إعداد العلمية المادة
/
أ
.
ا َّالفــر رفيق محمود
Remember that: question is the key of knowledge