Wednesday, May 14, 2014
Tuesday, May 13, 2014
Text File Reader Application using C#.NET Windows Form Application.
Open Visual Studio and create a new project.
Give a design to a form like this :-
private void button1_Click(object sender, EventArgs e)
{
if (File.Exists(textBox1.Text) == true)
{
StreamReader sr = new StreamReader(textBox1.Text);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();
}
else
{
MessageBox.Show("This file is not exist");
}
}
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
}
Give a design to a form like this :-
Now in the Code file add namespace :-
Using System.IO;Double click on Open button :-
private void button1_Click(object sender, EventArgs e)
{
if (File.Exists(textBox1.Text) == true)
{
StreamReader sr = new StreamReader(textBox1.Text);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();
}
else
{
MessageBox.Show("This file is not exist");
}
}
Double click on Clear button :-
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
}
Save it, Execute it and enjoy it :P :)
Sunday, May 11, 2014
How to create a Web Browser using C#.NET Windows Form Application....
Open Visual Studio.
New Project -> Windows Form Application.
Design the form as shown below:-
Double click on go button and write the following code :-
webBrowser1.Navigate(textBox1.Text);
Double click on back button :-
webBrowser1.GoBack();
Double click on forward button :-
webBrowser1.GoForward();
Double click on refresh button:-
webBrowser1.Refresh();
now select webbrowser control. Go to properties. Go to Event. Double click on Navigated Event :-
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
textBox1.Text = webBrowser1.Url.ToString();
}
Execute and enjoy browsing :p :)
New Project -> Windows Form Application.
Design the form as shown below:-
Double click on go button and write the following code :-
webBrowser1.Navigate(textBox1.Text);
Double click on back button :-
webBrowser1.GoBack();
Double click on forward button :-
webBrowser1.GoForward();
Double click on refresh button:-
webBrowser1.Refresh();
now select webbrowser control. Go to properties. Go to Event. Double click on Navigated Event :-
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
textBox1.Text = webBrowser1.Url.ToString();
}
Execute and enjoy browsing :p :)
Saturday, May 10, 2014
Email Sending Application(Only Gmail) Using C# Windows Application Form Part-2
Open Visual Studio.
New Project -> Windows Form Application.
Design form as shown below :-
using System.Net;
using System.Net.Mail;
namespace Email_Sending2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog d = new OpenFileDialog();
if (d.ShowDialog() == DialogResult.OK)
{
textUpload.Text = d.FileName.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
MailMessage mm = new MailMessage();
mm.Subject = textSub.Text;
mm.To.Add(textTo.Text);
mm.From = new MailAddress(textOwnMail.Text);
mm.Body = textMsg.Text;
Attachment a = new Attachment(textUpload.Text);
mm.Attachments.Add(a);
SmtpClient sc = new SmtpClient("smtp.gmail.com");
sc.EnableSsl = true;
sc.Credentials = new NetworkCredential(textOwnMail.Text, textOwnPw.Text);
sc.Port = 587;
sc.Send(mm);
MessageBox.Show("Your email sent successfully.");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
New Project -> Windows Form Application.
Design form as shown below :-
In the code file :-
using System.Net;
using System.Net.Mail;
namespace Email_Sending2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog d = new OpenFileDialog();
if (d.ShowDialog() == DialogResult.OK)
{
textUpload.Text = d.FileName.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
MailMessage mm = new MailMessage();
mm.Subject = textSub.Text;
mm.To.Add(textTo.Text);
mm.From = new MailAddress(textOwnMail.Text);
mm.Body = textMsg.Text;
Attachment a = new Attachment(textUpload.Text);
mm.Attachments.Add(a);
SmtpClient sc = new SmtpClient("smtp.gmail.com");
sc.EnableSsl = true;
sc.Credentials = new NetworkCredential(textOwnMail.Text, textOwnPw.Text);
sc.Port = 587;
sc.Send(mm);
MessageBox.Show("Your email sent successfully.");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
Execute the file and send Emails... Have a great day ! ♥
Simple Email Sending Application Using C# Windows Forms Application.
Open Visual Studio.
New Project -> Windows Form Application.
Design form as shown below :-
using System.Net;
using System.Net.Mail;
namespace Email_Sending
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
try
{
SmtpClient s = new SmtpClient("smtp.gmail.com");
s.Port = 587;
s.EnableSsl = true;
s.Timeout = 100000;
s.DeliveryMethod = SmtpDeliveryMethod.Network;
s.UseDefaultCredentials = false;
s.Credentials = new NetworkCredential("yourID@gmail.com", "YourPassword");
MailMessage mm = new MailMessage();
mm.To.Add(textBox1.Text);
mm.From = new MailAddress("YourID@gmail.com");
mm.Subject = textBox2.Text;
mm.Body = richTextBox1.Text;
Attachment a = new Attachment(textBox3.Text);
mm.Attachments.Add(a);
s.Send(mm);
MessageBox.Show("Your email sent successfully.");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog d = new OpenFileDialog();
if (d.ShowDialog() == DialogResult.OK)
{
textBox3.Text = d.FileName.ToString();
}
}
}
}
New Project -> Windows Form Application.
Design form as shown below :-
In the Code file :-
using System.Net;
using System.Net.Mail;
namespace Email_Sending
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
try
{
SmtpClient s = new SmtpClient("smtp.gmail.com");
s.Port = 587;
s.EnableSsl = true;
s.Timeout = 100000;
s.DeliveryMethod = SmtpDeliveryMethod.Network;
s.UseDefaultCredentials = false;
s.Credentials = new NetworkCredential("yourID@gmail.com", "YourPassword");
MailMessage mm = new MailMessage();
mm.To.Add(textBox1.Text);
mm.From = new MailAddress("YourID@gmail.com");
mm.Subject = textBox2.Text;
mm.Body = richTextBox1.Text;
Attachment a = new Attachment(textBox3.Text);
mm.Attachments.Add(a);
s.Send(mm);
MessageBox.Show("Your email sent successfully.");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog d = new OpenFileDialog();
if (d.ShowDialog() == DialogResult.OK)
{
textBox3.Text = d.FileName.ToString();
}
}
}
}
Run file and send email.... Enjoy Have a good day!
Advanced MessageBox in Windows Form Application using C#
Open Visual Studio.
File -> New Project -> Windows Form Application.
Give design to Form as Below :-
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("What ?", "What", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
}
private void button2_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("What ?", "What", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
switch(dr)
{
case DialogResult.Yes:
{
this.Text = "[YES]";
break;
}
case DialogResult.No:
{
this.Text = "[NO]";
break;
}
}
}
private void button3_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("What ?", "What", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
switch (dr)
{
case DialogResult.Yes:
{
MessageBox.Show("You clicked Yes");
break;
}
case DialogResult.No:
{
MessageBox.Show("You clicked No");
break;
}
}
}
}
File -> New Project -> Windows Form Application.
Give design to Form as Below :-
Double Click on Click1 Button and write following code :-
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("What ?", "What", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
}
Double click on Click2 Button and Write following code :-
private void button2_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("What ?", "What", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
switch(dr)
{
case DialogResult.Yes:
{
this.Text = "[YES]";
break;
}
case DialogResult.No:
{
this.Text = "[NO]";
break;
}
}
}
Again double click on Click3 Button and write following code :-
private void button3_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("What ?", "What", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
switch (dr)
{
case DialogResult.Yes:
{
MessageBox.Show("You clicked Yes");
break;
}
case DialogResult.No:
{
MessageBox.Show("You clicked No");
break;
}
}
}
}
Save it and run the file. Good Day :)
Splash Screen for Windows Form Application using C#
Open Visual Studio.
File-->New Project.
In the dialog box, choose windows forms application.
Form1.cs design page will be open.
After that design a form listed below:
File-->New Project.
In the dialog box, choose windows forms application.
Form1.cs design page will be open.
After that design a form listed below:
Add another form that will be used as the splash screen for this project. And name it as SplashScreen.cs .
Go to the properties of SplashScreen.cs and Change the FormBorderStyle to None. As well as change StartPosition to CenterScreen.
Now add PictureBox to SplashScreen form and add picture in the PictureBox as below :
Go to the file program.cs that contains the Main() method and make sure that the program starts with the SplashScreen form. Like :-
Application.Run(new SplashScreen());
Go to the SplashScreen form, click on "Events" and double-click on the "Shown" event.
Now add this Code there :-
public partial class SplashScreen : Form
{
Timer t;
public SplashScreen()
{
InitializeComponent();
}
private void SplashScreen_Shown(object sender, EventArgs e)
{
t = new Timer();
t.Interval=5000;
t.Start();
t.Tick += Tick1;
}
void Tick1(object sender, EventArgs e)
{
t.Stop();
Form1 f = new Form1();
f.Show();
this.Hide();
}
}
Now save all files and run the project... :)
Note :- "A splash screen is an image that appears while a game or program is loading." , "Splash screens are typically used by particularly large applications to notify the user that the program is in the process of loading." , "A splash screen disappears when the application's main window appears." , "Since splash screens often increase the wait for the desired content and may take a long time to load, they are not liked by all users."
Friday, May 9, 2014
Text to Speak windows form application in C#
Open Visual Studio.
File-->New Project.
In the dialog box, choose windows forms application.
Form1.cs design page will be open.
After that design a form listed below:
File-->New Project.
In the dialog box, choose windows forms application.
Form1.cs design page will be open.
After that design a form listed below:
Right click on Project-->Add Reference--->Then select System.Speech and click OK.
Then double click on Speak button and write code listed below:
//add new namespace
using System.Speech.Synthesis;
Then :-
private void button1_Click(object sender, EventArgs e)
{
SpeechSynthesizer s = new SpeechSynthesizer();
s.Speak(textBox1.Text);
}
Now run the application and enjoy. :P
Saturday, March 1, 2014
Simple example of Interface in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSharpInterface
{
interface mahi
{
void set();
}
class mahi1 : mahi
{
public void set()
{
Console.WriteLine("Hate the word LOVE");
Console.ReadLine();
}
}
class Program
{
static void Main(string[] args)
{
mahi1 m = new mahi1();
m.set();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSharpInterface
{
interface mahi
{
void set();
}
class mahi1 : mahi
{
public void set()
{
Console.WriteLine("Hate the word LOVE");
Console.ReadLine();
}
}
class Program
{
static void Main(string[] args)
{
mahi1 m = new mahi1();
m.set();
}
}
}
Output:
Simple example of Inheritance in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SimpleInheritance
{
class shape
{
public int height;
public int width;
public void setHeight(int h)
{
height = h;
}
public void setWidth(int w)
{
width = w;
}
}
class Area : shape
{
public int getArea()
{
return height * width;
}
}
class Program
{
static void Main(string[] args)
{
Area a = new Area();
a.setHeight(5);
a.setWidth(5);
Console.WriteLine("Area of Rectangle : {0}", a.getArea());
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SimpleInheritance
{
class shape
{
public int height;
public int width;
public void setHeight(int h)
{
height = h;
}
public void setWidth(int w)
{
width = w;
}
}
class Area : shape
{
public int getArea()
{
return height * width;
}
}
class Program
{
static void Main(string[] args)
{
Area a = new Area();
a.setHeight(5);
a.setWidth(5);
Console.WriteLine("Area of Rectangle : {0}", a.getArea());
Console.ReadLine();
}
}
}
Output:
Example of C# Structure.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSharpStruct
{
struct Books
{
public string title;
public string author;
public string subject;
public int id;
}
class Program
{
static void Main(string[] args)
{
Books b1, b2;
b1.title = "Little Inspiration";
b1.author = "Mahi";
b1.subject = "Quotes";
b1.id = 5;
Console.WriteLine("Book 1 title : {0}", b1.title);
Console.WriteLine("Book 1 author : {0}", b1.author);
Console.WriteLine("Book 1 subject : {0}", b1.subject);
Console.WriteLine("Book 1 book_id :{0}", b1.id);
Console.WriteLine();
b2.title = "Suvichar";
b2.author = "Jignesh Trivedi";
b2.subject = "Quotes";
b2.id = 10;
Console.WriteLine("Book 2 title : {0}", b2.title);
Console.WriteLine("Book 2 author : {0}", b2.author);
Console.WriteLine("Book 2 subject : {0}", b2.subject);
Console.WriteLine("Book 2 book_id : {0}", b2.id);
Console.ReadLine();
}
}
}
Output:
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSharpStruct
{
struct Books
{
public string title;
public string author;
public string subject;
public int id;
}
class Program
{
static void Main(string[] args)
{
Books b1, b2;
b1.title = "Little Inspiration";
b1.author = "Mahi";
b1.subject = "Quotes";
b1.id = 5;
Console.WriteLine("Book 1 title : {0}", b1.title);
Console.WriteLine("Book 1 author : {0}", b1.author);
Console.WriteLine("Book 1 subject : {0}", b1.subject);
Console.WriteLine("Book 1 book_id :{0}", b1.id);
Console.WriteLine();
b2.title = "Suvichar";
b2.author = "Jignesh Trivedi";
b2.subject = "Quotes";
b2.id = 10;
Console.WriteLine("Book 2 title : {0}", b2.title);
Console.WriteLine("Book 2 author : {0}", b2.author);
Console.WriteLine("Book 2 subject : {0}", b2.subject);
Console.WriteLine("Book 2 book_id : {0}", b2.id);
Console.ReadLine();
}
}
}
Output:
Example of String.Compare() in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringCompare
{
class Program
{
static void Main(string[] args)
{
string a = "Hello World";
string b = "Hello Friends";
if(String.Compare(a,b)==0)
{
Console.WriteLine(a+" and "+b+" are equal");
}
else
{
Console.WriteLine(a+" and "+b+" are not equal");
}
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringCompare
{
class Program
{
static void Main(string[] args)
{
string a = "Hello World";
string b = "Hello Friends";
if(String.Compare(a,b)==0)
{
Console.WriteLine(a+" and "+b+" are equal");
}
else
{
Console.WriteLine(a+" and "+b+" are not equal");
}
Console.ReadLine();
}
}
}
Output:
Thursday, February 27, 2014
Program of Method Overloading.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MethodOverloading
{
class test
{
public void show()
{
Console.WriteLine("No Parameter");
}
public void show(int a)
{
Console.WriteLine("One Parameter " + a);
}
public int show(int a, int b)
{
Console.WriteLine("Two Parameters are " + a + " and " + b);
return a + b;
}
public double show(double a, double b)
{
Console.WriteLine("Two Parameters are " + a + " and " + b);
return a + b;
}
}
class Program
{
static void Main(string[] args)
{
int sum;
double sum1;
test t = new test();
t.show();
t.show(10);
sum = t.show(10, 20);
Console.WriteLine(sum);
sum1 = t.show(10.5, 20.5);
Console.WriteLine(sum1);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MethodOverloading
{
class test
{
public void show()
{
Console.WriteLine("No Parameter");
}
public void show(int a)
{
Console.WriteLine("One Parameter " + a);
}
public int show(int a, int b)
{
Console.WriteLine("Two Parameters are " + a + " and " + b);
return a + b;
}
public double show(double a, double b)
{
Console.WriteLine("Two Parameters are " + a + " and " + b);
return a + b;
}
}
class Program
{
static void Main(string[] args)
{
int sum;
double sum1;
test t = new test();
t.show();
t.show(10);
sum = t.show(10, 20);
Console.WriteLine(sum);
sum1 = t.show(10.5, 20.5);
Console.WriteLine(sum1);
Console.ReadLine();
}
}
}
Output:
Simple Program of Constructor in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SimpleConstructorPro
{
class Program
{
private double length;
public Program()
{
Console.WriteLine(" Object is being created");
}
public void setLength(double len)
{
length = len;
}
public double getLength()
{
return length;
}
static void Main(string[] args)
{
Program p=new Program();
p.setLength(5.0);
Console.WriteLine(" Length of Program: "+p.getLength());
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SimpleConstructorPro
{
class Program
{
private double length;
public Program()
{
Console.WriteLine(" Object is being created");
}
public void setLength(double len)
{
length = len;
}
public double getLength()
{
return length;
}
static void Main(string[] args)
{
Program p=new Program();
p.setLength(5.0);
Console.WriteLine(" Length of Program: "+p.getLength());
Console.ReadLine();
}
}
}
Output:
Program to addition of all elements of array C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArrayElementsAddition
{
class Program
{
static void Main(string[] args)
{
int[,] a = new int[5, 2];
int i, j, sum = 0;
for (i = 0; i < 5; i++)
{
for (j = 0; j < 2; j++)
{
a[i, j] = Convert.ToInt32(Console.ReadLine());
}
}
Console.WriteLine("Array Elements");
for (i = 0; i < 5; i++)
{
for (j = 0; j < 2; j++)
{
Console.Write(" " + a[i, j]);
}
Console.WriteLine();
}
for (i = 0; i < 5; i++)
{
for (j = 0; j < 2; j++)
{
sum = sum + a[i, j];
}
}
Console.WriteLine("Sum: " + sum);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArrayElementsAddition
{
class Program
{
static void Main(string[] args)
{
int[,] a = new int[5, 2];
int i, j, sum = 0;
for (i = 0; i < 5; i++)
{
for (j = 0; j < 2; j++)
{
a[i, j] = Convert.ToInt32(Console.ReadLine());
}
}
Console.WriteLine("Array Elements");
for (i = 0; i < 5; i++)
{
for (j = 0; j < 2; j++)
{
Console.Write(" " + a[i, j]);
}
Console.WriteLine();
}
for (i = 0; i < 5; i++)
{
for (j = 0; j < 2; j++)
{
sum = sum + a[i, j];
}
}
Console.WriteLine("Sum: " + sum);
Console.ReadLine();
}
}
}
Output:
Program to manage elements in ascending order Array C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArrayAsscendingOrder
{
class Program
{
static void Main(string[] surat)
{
int[] a = new int[10];
int t, i, j;
for (i = 0; i < 5; i++)
a[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Array Element");
for (i = 0; i < 5; i++)
Console.WriteLine(a[i]);
Console.WriteLine("Array After Sorting");
for (i = 0; i < 5; i++)
{
for (j = 0; j < i; j++)
{
if (a[i] < a[j])
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
for (i = 0; i < 5; i++)
{
Console.WriteLine(a[i]);
}
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArrayAsscendingOrder
{
class Program
{
static void Main(string[] surat)
{
int[] a = new int[10];
int t, i, j;
for (i = 0; i < 5; i++)
a[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Array Element");
for (i = 0; i < 5; i++)
Console.WriteLine(a[i]);
Console.WriteLine("Array After Sorting");
for (i = 0; i < 5; i++)
{
for (j = 0; j < i; j++)
{
if (a[i] < a[j])
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
for (i = 0; i < 5; i++)
{
Console.WriteLine(a[i]);
}
Console.ReadLine();
}
}
}
Output:
Program to find the element is present in array or not.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArrayElementPresent
{
class Program
{
static void Main(string[] args)
{
int[] a1 = new int[] { 10, 20, 30, 40, 50 };
int i, b, pos;
for (i = 0; i < 5; i++)
Console.WriteLine(a1[i]);
Console.WriteLine("Enter Element: ");
b = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < 5; i++)
if (a1[i] == b)
Console.WriteLine("Element Present");
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArrayElementPresent
{
class Program
{
static void Main(string[] args)
{
int[] a1 = new int[] { 10, 20, 30, 40, 50 };
int i, b, pos;
for (i = 0; i < 5; i++)
Console.WriteLine(a1[i]);
Console.WriteLine("Enter Element: ");
b = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < 5; i++)
if (a1[i] == b)
Console.WriteLine("Element Present");
Console.ReadLine();
}
}
}
Output:
Thursday, February 20, 2014
Another simple program of variables (addition,multiplication,subtraction,division)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AddSubMulDiv
{
class Program
{
static void Main(string[] args)
{
int a = 10;
int b = 5;
int add = a + b;
int sub = a - b;
int mul = a * b;
int div = a / b;
Console.WriteLine();
Console.WriteLine(" Addition : " + add);
Console.WriteLine();
Console.WriteLine(" Subtraction : " + sub);
Console.WriteLine();
Console.WriteLine(" Multiplication : " + mul);
Console.WriteLine();
Console.WriteLine(" Division : " + div);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AddSubMulDiv
{
class Program
{
static void Main(string[] args)
{
int a = 10;
int b = 5;
int add = a + b;
int sub = a - b;
int mul = a * b;
int div = a / b;
Console.WriteLine();
Console.WriteLine(" Addition : " + add);
Console.WriteLine();
Console.WriteLine(" Subtraction : " + sub);
Console.WriteLine();
Console.WriteLine(" Multiplication : " + mul);
Console.WriteLine();
Console.WriteLine(" Division : " + div);
Console.ReadLine();
}
}
}
Output:
Example of Dynamic initialization in C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DynamicInitialization
{
class Program
{
static void Main(string[] args)
{
double s1 = 5.5, s2 = 10.10;
double hypot = Math.Sqrt((s1 * s1) + (s2 * s2));
Console.Write("Hypotenuse of triangle with sides " +s1 + " by " + s2 + " is " + hypot);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DynamicInitialization
{
class Program
{
static void Main(string[] args)
{
double s1 = 5.5, s2 = 10.10;
double hypot = Math.Sqrt((s1 * s1) + (s2 * s2));
Console.Write("Hypotenuse of triangle with sides " +s1 + " by " + s2 + " is " + hypot);
Console.ReadLine();
}
}
}
Output:
Example of Assign value to C# variable.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ValueVariable
{
class Program
{
static void Main(string[] args)
{
int a, b;
a = 20;
Console.WriteLine("Value of A = " + a);
b = a / 2;
Console.WriteLine("Value of B = " + b +" (a/2)");
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ValueVariable
{
class Program
{
static void Main(string[] args)
{
int a, b;
a = 20;
Console.WriteLine("Value of A = " + a);
b = a / 2;
Console.WriteLine("Value of B = " + b +" (a/2)");
Console.ReadLine();
}
}
}
Output:
Subscribe to:
Posts (Atom)