Академический Документы
Профессиональный Документы
Культура Документы
1.
Integrated Development Environment (IDE) for C#
The last two are freely available from Microsoft official website.
Using these tools, you can write all kinds of C# programs from
simple command-line applications to more complex applications.
You can also write C# source code files using a basic text editor, like
notepad, and compile the code into assemblies using the command-
line compiler, which is gain a part of the .Net Framework.
2.
C# - Program Structure
- Namespace declaration
- A class
- Class methods
- Class attributes
- A main method
- Statements & expressions
- Comments
Let us look at a simple code that would print the words “Hello
World”.
Using system;
Namespace HelloWorldApplication
{
Class HelloWorld
{
Static void main(String[] args)
{
/* my first program in C# */
Console.WriteLine(“Hello World”);
Console.ReadKey();
}
}
}
Hello World
3.
Let us look at various parts of the above program:
4.
Date Types:
the value types deirectly contain data. Some examples are Int, Char,
Float, which stores numbers, alphabets, floating point numbers,
respectively. When you declare an Int type, the system allocates
memory to store the value.
5.
Operators
An operator is a sysmbol that tells the compiler to perform specific
mathematical or logical manipulations. C# is rich in built-in
operators and provides the following type of operators:
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
Arithmetic Operators
+ Adds to Operands A + B will give
30
- Subtracts second operand from first A-B will give -10
* Multiplies both operands A*B will give
200
/ Divides numerator by de-numerator B/A will give 2
% Modulus operator and remainder of after an B%A will give 0
integer division
++ Increment operator increases integer value by one A++ will give 11
-- Decrement operator decreases integer value by A—will give 9
one
Relational Operator
== Checks if the values of two operands are equal or not, if yes then condition (A==B)i
becomes true s not
true
!= Checks if the values of two operands are equal or not, if values are not (A!=B)i
equal then condition becomes true s true
> Checks if the value of left operand is greater than the value of right (A>B) is
operand, if yes then condition becomes true not
true
< Checks if the value of left operand is less than the value of right operand, if (A<B)is
yes then condition becomes true true
>= Checks if the value of left operand is greater than or equal to the value of (A>=B)i
right operand, if yes then condition becomes true s not
true
<= Checks if the value of left operand is less than or equal to the value of right (A<=B)i
operand, if yes then condition becomes true s true
6.
Logical Operator
&& Called logical and operator. If both the operands (A&&B)
are non zero then condition becomes true is false
|| Called logical OR operator. If any of the two (A||B)i
operands is non zero then condition becomes s True
true.
Called Logical NOT operator. Use to reverses the !(A&&
! logical state of its operand. If a condition is true B)is
then logical NOT operator will make false true.
Bitwise Operator
& Binary AND operator copies a bit to (A & B)will give 12.
the result if it exists in both Which is 0000 1100
operands.
| Binary OR operator copies a bit if it (A|B) will give 61,
exists in either operand. which is 0011 1101
ᶺ Binary XOR operator copies the bit if (AᶺB)will give 49,
it is set in one operand but not both.which is 0011 0001
~ Binary Ones complement operator is (~A)will give -61,
unary and has the effect of flipping which is 1100 0011
bits in 2’s complement
due to a signed
binary number
<< Binary left shift operator. The left A<<2 will give 240,
operands value is moved left by the which is 1111 0000
number of bits specified by the right
operand
>> Binary right shift operator. The left A>>2 will give 15,
operands value is moved right by the which is 0000 1111
number of bits specified by the right
operand.
7.
Assignment Operators
8.
Decision Making
Condition
Conditional code
9.
C# Provides following types of decision making statements
Loops
10.
Conditional code
If condition is true
Condition
If condition is false
11.
Windows Form Application
12.
Partial Classes
13.
Windows Form Application I.D.E
14.
Designing a User Interface
Adding Controls
In either designer, you use the mouse to drag controls, which are
components with visual representation such as buttons and text
boxes, onto a design surface. The following illustration shows a
combo box that has been dragged from the Toolbox window onto a
form in the Windows Forms Designer.
15.
Setting Properties Project 2: Grading System
After you add a control to the design surface, you can use the Output:
Properties window to set its properties, such as background
x
color and default text.
Student Name:: Total Grades:
In the Windows Form designer, the values that you specify in
the Properties window are the initial values that will be Student Number: Equivalent:
assigned to that property when the control is created at run
time. In the WPF designer, the values that you specify in the Course: Remarks:
Properties window are stored as attributes in the window's
XAML file. Prelim: Compute
16.
Button
Textbox
Label
Combo Box
List Box
Timer
Output:
Addition:
Subtraction:
Multiplication:
Division:
Formula:
Addition: 1st Number + 2nd Number
Subtraction: 1st Number - 2nd Number
Multiplication: 1st Number * 2nd Number
Division: 1st Number / 2nd Number
Exercise 3: input 1st number and 2nd number then display to Using system;
messagebox the sum of two input number, subtract the two input Namespace Application1
number, multiply the two input number and divide the two input {
number. follow the figure below: Class program
{
x Static void main(string[] args)
{
Compute
x
Enter age: 18 }
}
Remarks: Qualified to vote }
Code:
Click
Exercise 2: Reverse 3 digit Number Windows Form Application
Output: Exercise 1: input your name and click the click button then show to
messagebox the input name
Codes:
Namespace ConsoleApplication1 Enter Your Name: Your name
{
Class Program
{
Click
Static void main(String[] args)
{ x
Hello….Your Name
Exercise 2: input your name and click the click button then show to
Another Textbox the input name
Click
Exercise 3: Reverse 4 digit Number
Output:
Codes:
Namespace ConsoleApplication1
{
Class Program
{
Static void main(String[] args)
{
}
}
}
} Exercise 4: Reverse 5 digit Number
}
} Output:
Input 5 Digit Number:
Reverse:
Codes:
Namespace ConsoleApplication1
{
Class Program
{
Static void main(String[] args)
{
}
}
}
Exercise 5: College Billing
Output:
Formula:
Balance=Tuition Fee – Down Payment
Prelim=balance/3
Midterm=balance/3
Finals=balance/3
Codes:
Namespace ConsoleApplication1
{
Class Program
{
Static void main(String[] args)
{
}
}
}
Exercise 5: College Billing
Output:
Total Grades:
Equivalent:
Remarks:
Formula:
Total Grades=(prelim + midterm + finals)/3
Equivalent:
Grades Equivalent
100-99 - 1.00
98-96 - 1.25
93-95 - 1.50
90-92 - 1.75
87-89 - 2.00
84-86 - 2.25
81-83 - 2.50
78-80 - 2.75
75-77 - 3.00
74-below - 5.00
Remarks:
Total Grade>=75 - Passed
Total grade<=75 - Failed
Codes:
Namespace ConsoleApplication1
{
Class Program
{
Static void main(String[] args)
{
}
}
}
Exercise 7: Voting Program
Output:
Voting Program
Input Age:
Remarks:
}
}
}
Exercise 8: Simple Payroll System
Output:
Basic Pay:
SSS(10%):
Philhealth(20%):
Pag-ibig(30%):
Total Deduction:
Net Pay:
Formula:
Basic Pay=Rate per hout*Total Hour
Total Deduction=(SSS+Philhealth+Pagibig)
Output: Output:
Leap Year/Not Leap Year Saint John Bosco
Input a year to check if it is leap year or not leap year List of Activity
Codes:
Namespace ConsoleApplication1
{
Class Program
{
Static void main(String[] args)
{
}
}
}