aaaaaaaaaaaaaaaaa
The following program printing Hello World!
on the output
screen.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!"); //printing this line on output screen.
Console.ReadKey();
}
}
}
The following program also printing Hello World
in one line on
the output screen.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{ //it printing 'Hello World!'.
Console.Write("Hello "); //when U write 'Write' it printing all text on one line.
Console.WriteLine("World!"); //when U add 'Line' to 'Write' mean' 'WriteLine'
//write combine then it going to new line.
//'Line' means go to new line.
Console.ReadLine();
}
}
}
The following program printing Hello World!
in two lines on the
output screen.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{ //it printing 'Hello
// World!'
Console.WriteLine("Hello "); //'WriteLine' means goto new line after printing
//printing this line.
Console.WriteLine("World!");
Console.ReadKey();
} //U also write 'Console.Write("Hello\n ");'
} //'Console.Write("World");' or 'Console.WriteLine("Hello\n World!");'
} //'Console.Write("Hello\n World!");' //'\n' means goto new line.
Although the first several programs display output in the command prompt, most C#
applications use windows or dialogs to display output. As mentioned earlier, dialogs are
windows that typically display important messages to the user of an application. The .NET
Framework Class Library includes class MessageBox for creating dialogs. Class MessageBox
is defined in namespace System.Windows.Forms. The program displays the same string as in
a message dialog using class MessageBox
.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms; //this is library of Windows Form must use it for Message Box
//bcz message box belong from Windows Form.
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
MessageBox.Show("Hello\World!"); //it printing 'Hello World!' in two
} //lines in Message Box, 'Message Box.Show' used for showing in message box.
}
}
This program will give an error because many compiled classes in C# (including MessageBox) need to be
referenced before they can be used in a program. Depending on the type of application we
create, classes may be compiled into files with a .exe
(executable) extension, a .dll
(or dynamic link library) extension or one of several other extensions.
Goto Project
and Select the Add Reference...
option from the Project menu, This opens the Add Reference
dialog, in Add Reference dialog
click on .NET
and Double click on System.Windows.Forms.dll
to add this file to the
Selected Components list at the bottom of the dialog, then click OK to Run the Program.