Welcome to Aquilano`s Blog

C# sample programs

C# allows us to write programs like Console Bases Applications as well as Windows Based Applications .The following links give you a basic idea of Console Based Application and Windows Based Application.


C# console based application
The following program is a simple console based CSharp application. The program starts from the main() method. Create a new Console Application project and copy and paste the following C# source code.
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
 class Program
 {
  static void Main(string[] args)
  {
   Console.WriteLine("My First Program");
   Console.ReadKey();
  }
 }
}
When you execute this C# program you will get   "This is my first program" in the console and the 
system wait for the input from the user.
Console.ReadKey() is waiting for user input.

C# windows based application
The following program is a sample Windows Based C# application. Create a new C# Windows Application project and copy and paste the following source code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
 public partial class Form1 : Form
 {
  public Form1()
  {
   InitializeComponent();
  }

  private void button1_Click(object sender, EventArgs e)
  {
   MessageBox.Show("This is my first program");
  }
 }
}
When you execute this C# program you will get the message "This is my first program" in message box.

0 komentar:

Posting Komentar