SlideShare a Scribd company logo
Renas R. Rekany Object-Oriented-Programming
1
Programming Language with
C_Sharp
Object-Oriented-Programming
Renas R. Rekany
Renas R. Rekany Object-Oriented-Programming
2
Beginning C# programming fundamentals
1- Name Spaces:
The namespace keyword is used to declare a scope that contains a set of related
objects. You can use a namespace to organize code elements and to create globally
unique types.
2- Conversion:
You can convert a string to a number by using methods in the Convert class. Such a
conversion can be useful when obtaining numerical input from a command line
argument, for example. The following table lists some of the methods that you can
use.
2.1 Convert Class
Numeric Type Method
decimal ToDecimal(String)
float ToSingle(String)
double ToDouble(String)
short ToInt16(String)
int ToInt32(String)
long ToInt64(String)
Renas R. Rekany Object-Oriented-Programming
3
ushort ToUInt16(String)
uint ToUInt32(String)
ulong ToUInt64(String)
Structure Conversion Method
Decimal static decimal Parse(string str)
Double static double Parse(string str)
Single static float Parse(string str)
Int64 static long Parse(string str)
Int32 static int Parse(string str)
Int16 static short Parse(string str)
UInt64 static ulong Parse(string str)
UInt32 static uint Parse(string str)
UInt16 static ushort Parse(string str)
Byte static byte Parse(string str)
bool static bool Parse(string str)
SByte static sbyte Parse(string str)
Renas R. Rekany Object-Oriented-Programming
4
Example1:
3- Relational Operator:
In most cases, the Boolean expression, used by the if statement, uses relation
operators
string name;
int mark;
name ="Redwan"
mark = Int32.Parse(85);
textbox1.text=name;
textbox2.text=Convert.ToString(mark);
Renas R. Rekany Object-Oriented-Programming
5
4- Boolean Expressions:
A Boolean expression is any variable or calculation that results in a true or false
condition.
Renas R. Rekany Object-Oriented-Programming
6
5- Condition control structure
Thus far, within a given function, instructions have been executed sequentially, in
the same order as written. Of course that is often appropriate! On the other hands if
you are planning out instructions, you can get to a place where you say, “Hm, that
depends....”, and a choice must be made. The simplest choices are two-way: do one
thing is a condition is true, and another (possibly nothing) if the condition is not true.
5.1The if Statement
The if statement decides whether a section of code executes or not. The if statement
uses a Boolean to decide whether the next statement or block of statements executes.
The general C# if syntax is:
if (expression )
{Statement(s) for if-true}
Example2:
5.2 if-else Statements
The general C# if-else syntax is
if (expression )
{Statement(s) for if-true}
else
{statement(s) for if-false}
Example3:
int x=2,y=4;
if(x>y)
MessageBox.Show("True");
int x=2,y=4;
if(x>y)
MessageBox.Show("True");
else
MessageBox.Show("False");
Renas R. Rekany Object-Oriented-Programming
7
5.3 if-else-if Statements
if (expression_1)
{
statement;
statement;
etc.
}
else if (expression_2)
{
statement;
statement;
etc.
}
else
{
statement;
statement;
etc
Example4:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Otherwise, if expression_2 is true these statements
are executed, and the rest of the structure is
ignored.
Insert as many else if clauses as necessary.
These statements are executed if none of the
expressions above are true.
If expression_1 is true these statements are
executed, and the rest of the structure is ignored.
Renas R. Rekany Object-Oriented-Programming
8
int a, b, c;
a = Convert.ToInt32(textBox2.Text);
b = Convert.ToInt32(textBox3.Text);
if (Convert.ToInt32(textBox1.Text) == 1)
{
c = a + b;
textBox4.Text = Convert.ToString(c);
}
else if (Convert.ToInt32(textBox1.Text)==2)
{
c=a-b;
textBox4.Text=Convert.ToString(c);
}
else if (Convert.ToInt32(textBox1.Text) == 3)
{
c = a * b;
textBox4.Text = Convert.ToString(c);
}
else if (Convert.ToInt32(textBox1.Text) == 4)
{
c = a / b;
textBox4.Text = Convert.ToString(c);
}
}
}
}
Example5 (Switch- Condition):
switch (value)
{
case value 1:
Console.WriteLine(1);
break;
case value 2:
Console.WriteLine(5);
break;
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
Renas R. Rekany Object-Oriented-Programming
9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int a, b, c;
a = Convert.ToInt32(textBox2.Text);
b = Convert.ToInt32(textBox3.Text);
switch (Convert.ToInt32(textBox1.Text))
{
case 1:
c = a + b;
textBox4.Text = Convert.ToString(c);
break;
case 2:
c = a - b;
textBox4.Text = Convert.ToString(c);
break;
case 3:
c = a * b;
textBox4.Text = Convert.ToString(c);
break;
case 4:
c = a / b;
textBox4.Text = Convert.ToString(c);
break;
}
}
}
}
OUTPUT:

More Related Content

PDF
C interview-questions-techpreparation
PDF
The Expression Problem - Part 2
DOCX
Declaration programming 2017
PPTX
Clean code
PDF
Introduction to c programming
PPTX
Introduction To Programming with Python-1
PPS
C programming session 09
PPTX
Optimization of dfa
C interview-questions-techpreparation
The Expression Problem - Part 2
Declaration programming 2017
Clean code
Introduction to c programming
Introduction To Programming with Python-1
C programming session 09
Optimization of dfa

What's hot (20)

PPT
String Matching with Finite Automata,Aho corasick,
PPTX
Introduction To Programming with Python Lecture 2
PPTX
Input processing and output in Python
PPT
Regular expressions and languages pdf
PPS
C programming session 01
PDF
Lesson 03 python statement, indentation and comments
PPT
Chapter Two(1)
PPTX
Regular expressions in Python
PPT
Applying Generics
DOCX
What is c language
PPT
Chapter Three(2)
PDF
Complex C-declarations & typedef
PPTX
Chapter 9 python fundamentals
PDF
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
PPTX
Copy propagation
PDF
C programming & data structure [character strings & string functions]
String Matching with Finite Automata,Aho corasick,
Introduction To Programming with Python Lecture 2
Input processing and output in Python
Regular expressions and languages pdf
C programming session 01
Lesson 03 python statement, indentation and comments
Chapter Two(1)
Regular expressions in Python
Applying Generics
What is c language
Chapter Three(2)
Complex C-declarations & typedef
Chapter 9 python fundamentals
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
Copy propagation
C programming & data structure [character strings & string functions]
Ad

Similar to C# p5 (20)

PDF
Computer science_xii_2016
PDF
Programming in C Session 1
PDF
if else python.pdf
PDF
C Languages FAQ's
PPTX
Core Java and Data Structure using C++.pptx
DOCX
Notes on c++
PPT
Flow of Control
PPTX
Programming Fundamentals
PPTX
C presentation! BATRA COMPUTER CENTRE
PPTX
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
DOCX
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
PPTX
C Programming Unit-2
PPTX
Advanced VB: Review of the basics
PPTX
Advanced VB: Review of the basics
PPTX
c & c++ logic building concepts practice.pptx
DOCX
C# language basics (Visual Studio)
DOCX
C# language basics (Visual studio)
PDF
qb unit2 solve eem201.pdf
PPTX
c-programming functions in c programming.pptx
PPTX
session-1_Design_Analysis_Algorithm.pptx
Computer science_xii_2016
Programming in C Session 1
if else python.pdf
C Languages FAQ's
Core Java and Data Structure using C++.pptx
Notes on c++
Flow of Control
Programming Fundamentals
C presentation! BATRA COMPUTER CENTRE
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C Programming Unit-2
Advanced VB: Review of the basics
Advanced VB: Review of the basics
c & c++ logic building concepts practice.pptx
C# language basics (Visual Studio)
C# language basics (Visual studio)
qb unit2 solve eem201.pdf
c-programming functions in c programming.pptx
session-1_Design_Analysis_Algorithm.pptx
Ad

More from Renas Rekany (20)

PDF
decision making
PDF
Artificial Neural Network
PDF
AI heuristic search
PDF
AI local search
PDF
AI simple search strategies
PDF
PDF
PDF
PDF
PDF
PDF
PDF
PDF
PDF
C# with Renas
PDF
Object oriented programming inheritance
PDF
Object oriented programming
PDF
Renas Rajab Asaad
PDF
Renas Rajab Asaad
PDF
Renas Rajab Asaad
PDF
Renas Rajab Asaad
decision making
Artificial Neural Network
AI heuristic search
AI local search
AI simple search strategies
C# with Renas
Object oriented programming inheritance
Object oriented programming
Renas Rajab Asaad
Renas Rajab Asaad
Renas Rajab Asaad
Renas Rajab Asaad

Recently uploaded (20)

PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Computing-Curriculum for Schools in Ghana
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
PDF
My India Quiz Book_20210205121199924.pdf
PDF
Empowerment Technology for Senior High School Guide
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
20th Century Theater, Methods, History.pptx
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PPTX
Introduction to pro and eukaryotes and differences.pptx
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
LDMMIA Reiki Yoga Finals Review Spring Summer
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Computing-Curriculum for Schools in Ghana
Paper A Mock Exam 9_ Attempt review.pdf.
Unit 4 Computer Architecture Multicore Processor.pptx
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Weekly quiz Compilation Jan -July 25.pdf
TNA_Presentation-1-Final(SAVE)) (1).pptx
My India Quiz Book_20210205121199924.pdf
Empowerment Technology for Senior High School Guide
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
B.Sc. DS Unit 2 Software Engineering.pptx
What if we spent less time fighting change, and more time building what’s rig...
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
Chinmaya Tiranga quiz Grand Finale.pdf
20th Century Theater, Methods, History.pptx
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Introduction to pro and eukaryotes and differences.pptx
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...

C# p5

  • 1. Renas R. Rekany Object-Oriented-Programming 1 Programming Language with C_Sharp Object-Oriented-Programming Renas R. Rekany
  • 2. Renas R. Rekany Object-Oriented-Programming 2 Beginning C# programming fundamentals 1- Name Spaces: The namespace keyword is used to declare a scope that contains a set of related objects. You can use a namespace to organize code elements and to create globally unique types. 2- Conversion: You can convert a string to a number by using methods in the Convert class. Such a conversion can be useful when obtaining numerical input from a command line argument, for example. The following table lists some of the methods that you can use. 2.1 Convert Class Numeric Type Method decimal ToDecimal(String) float ToSingle(String) double ToDouble(String) short ToInt16(String) int ToInt32(String) long ToInt64(String)
  • 3. Renas R. Rekany Object-Oriented-Programming 3 ushort ToUInt16(String) uint ToUInt32(String) ulong ToUInt64(String) Structure Conversion Method Decimal static decimal Parse(string str) Double static double Parse(string str) Single static float Parse(string str) Int64 static long Parse(string str) Int32 static int Parse(string str) Int16 static short Parse(string str) UInt64 static ulong Parse(string str) UInt32 static uint Parse(string str) UInt16 static ushort Parse(string str) Byte static byte Parse(string str) bool static bool Parse(string str) SByte static sbyte Parse(string str)
  • 4. Renas R. Rekany Object-Oriented-Programming 4 Example1: 3- Relational Operator: In most cases, the Boolean expression, used by the if statement, uses relation operators string name; int mark; name ="Redwan" mark = Int32.Parse(85); textbox1.text=name; textbox2.text=Convert.ToString(mark);
  • 5. Renas R. Rekany Object-Oriented-Programming 5 4- Boolean Expressions: A Boolean expression is any variable or calculation that results in a true or false condition.
  • 6. Renas R. Rekany Object-Oriented-Programming 6 5- Condition control structure Thus far, within a given function, instructions have been executed sequentially, in the same order as written. Of course that is often appropriate! On the other hands if you are planning out instructions, you can get to a place where you say, “Hm, that depends....”, and a choice must be made. The simplest choices are two-way: do one thing is a condition is true, and another (possibly nothing) if the condition is not true. 5.1The if Statement The if statement decides whether a section of code executes or not. The if statement uses a Boolean to decide whether the next statement or block of statements executes. The general C# if syntax is: if (expression ) {Statement(s) for if-true} Example2: 5.2 if-else Statements The general C# if-else syntax is if (expression ) {Statement(s) for if-true} else {statement(s) for if-false} Example3: int x=2,y=4; if(x>y) MessageBox.Show("True"); int x=2,y=4; if(x>y) MessageBox.Show("True"); else MessageBox.Show("False");
  • 7. Renas R. Rekany Object-Oriented-Programming 7 5.3 if-else-if Statements if (expression_1) { statement; statement; etc. } else if (expression_2) { statement; statement; etc. } else { statement; statement; etc Example4: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Otherwise, if expression_2 is true these statements are executed, and the rest of the structure is ignored. Insert as many else if clauses as necessary. These statements are executed if none of the expressions above are true. If expression_1 is true these statements are executed, and the rest of the structure is ignored.
  • 8. Renas R. Rekany Object-Oriented-Programming 8 int a, b, c; a = Convert.ToInt32(textBox2.Text); b = Convert.ToInt32(textBox3.Text); if (Convert.ToInt32(textBox1.Text) == 1) { c = a + b; textBox4.Text = Convert.ToString(c); } else if (Convert.ToInt32(textBox1.Text)==2) { c=a-b; textBox4.Text=Convert.ToString(c); } else if (Convert.ToInt32(textBox1.Text) == 3) { c = a * b; textBox4.Text = Convert.ToString(c); } else if (Convert.ToInt32(textBox1.Text) == 4) { c = a / b; textBox4.Text = Convert.ToString(c); } } } } Example5 (Switch- Condition): switch (value) { case value 1: Console.WriteLine(1); break; case value 2: Console.WriteLine(5); break; } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1
  • 9. Renas R. Rekany Object-Oriented-Programming 9 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { int a, b, c; a = Convert.ToInt32(textBox2.Text); b = Convert.ToInt32(textBox3.Text); switch (Convert.ToInt32(textBox1.Text)) { case 1: c = a + b; textBox4.Text = Convert.ToString(c); break; case 2: c = a - b; textBox4.Text = Convert.ToString(c); break; case 3: c = a * b; textBox4.Text = Convert.ToString(c); break; case 4: c = a / b; textBox4.Text = Convert.ToString(c); break; } } } } OUTPUT: