Professional Documents
Culture Documents
Open Source Application CSharp
Open Source Application CSharp
• Visual Basic, Visual C#, and Visual C++ all use the
same integrated development environment (IDE),
which enables tool sharing and eases the creation of
mixed-language solutions.
C# INTRODUCTION
• is a simple, modern, general-purpose, object-oriented
programming language developed by Microsoft within
its .NET initiative led by Anders Hejlsberg.
Return type: A method may return a value. The return type is the data
type of the value the method returns. If the method is not returning
any values, then the return type is void.
class Program
{
public static void Main(string[] args)
{
int val1 = 0, val2 = 0;
//accept value1 from the user
Console.WriteLine("Enter first value");
val1 = Convert.ToInt32(Console.ReadLine());
//accept value2 from the user
Console.WriteLine("Enter first value");
val2= Convert.ToInt32(Console.ReadLine());
Program ename = new Program();
ename.sum(val1, val2);
Console.ReadKey();
}
public void sum( int num1, int num2)
{
int add = (num1 + num2);
Console.WriteLine("Total is:{0}", add);
}
class Program
{
public static void Main(string[] args)
{
int val1 = 0, val2 = 0;
string fullname;
//accept value1 from the user
Console.WriteLine("Enter first value");
val1 = Convert.ToInt32(Console.ReadLine());
//accept value2 from the user
Console.WriteLine("Enter first value");
val2= Convert.ToInt32(Console.ReadLine());
Program ename = new Program();
ename.sum(val1, val2);
Console.WriteLine("Type your name:");
fullname = Convert.ToString(Console.ReadLine());
ename.info(fullname);
Console.ReadKey();
}
public void sum( int num1, int num2)
{
int add = (num1 + num2);
Console.WriteLine("Total is:{0}", add);
}
public void info(string name)
{
Console.WriteLine("Good day:{0}", name);
}
C# IDE
IDE PARTS
1. Menu Bar
2. Standard Toolbar
3. ToolBox
4. Forms Designer
5. Output Window
6. Solution Explorer
7. Properties Window
C# Windows Forms
The first step is to start a new project and build a form.
Open your Visual Studio and select File->New Project
and from the new project dialog box select Other
Languages->Visual C# and select Windows Forms
Application.
For example, if you want to change the back color of the
form to Brown, you can code in the Form1_Load event
like the following.
Open newform
var nextform = new Form2();
nextform.Show();
this.Hide();
answer = firstTextBoxNumber + secondTextBoxNumber;
int TF, Down, Cash, Change;
TF = int.Parse(tFTextBox.Text );
Down = int.Parse(downTextBox.Text);
Cash = int.Parse(cashTextBox.Text);
Change = (Cash - TF);
MessageBox.Show(Change.ToString());
downTextBox.Text =(Change.ToString());
COMPUTE
int num1, num2, sum;
num1 = int.Parse(textBox1.Text);
num2 = int.Parse(textBox2.Text);
sum = (num1 + num2);
MessageBox.Show("sum" + sum);
textBox4.Text = (sum.ToString());
CLEAR
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
pictureBox1.Visible = false;
pictureBox2.Visible = false;
Combo box
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedItem == "Meal 1")
{
textBox3.Text = "500";
}
else if (comboBox1.SelectedItem == "Meal 2")
{
textBox4.Text = "600";
}
else if (comboBox1.SelectedItem == "Meal 3")
{
textBox5.Text = "1000";
}
}
private void Form3_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("Meal 1");
comboBox1.Items.Add("Meal 2");
comboBox1.Items.Add("Meal 3");
pictureBox1.Visible = false;
pictureBox2.Visible = false;
C# Label Control