Monday, February 28, 2011

C# console application

Hello every one let's start
Here we will write our first application in c# this is a sample application as console application
It's very easy app
Please open new project as C# console application now we will write hello world application in c#
When u open it u will see this:

Code:
using System;           // this is the default namespaces written in code
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HelloWorld          // HelloWorld this is the name of the class
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World");        // message that printed in command prompt screen or black screen
        }
    }
}

Please When U run the project Run it as Start Without debuging mode to see What u Write

Let's see the command prompt Write Hello World

What if u want to enter any thing and then print it on screen
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            String str = "";
            Console.WriteLine("Please Enter Your Name: ");
            str=Console.ReadLine();
            Console.WriteLine("Hello : {0}",str);
        }
    }
}


Please Note That C# Language is a case sensetive language that's mean Sam not sam Not SaM
In second code we use String AS a data type String str mean create location in memory to whole text buffer only
The all Names in c# is:

abstract const extern int out short typeof
as continue false interface override sizeof uint
base
decimal
finally
internal
params
stackalloc
ulong

bool
default
fixed is
private
static
unchecked
break
delegate
float
lock
protected
string
unsafe

byte
do
for
long
public
struct
ushort

case
double
foreach
namespace
readonly
switch
using

catch
else
goto
new
ref
this
virtual

char
enum
if
null
return
throw
void

checked
event
implicit
object
sbyte
true
volatile
class
explicit
in
operator
sealed
try
while


Besides these keywords, C# has other words that should be reserved only depending on how and where they are used. These are referred to as contextual keywords and they are:
get
partial
set
value
where
yield

No comments:

Post a Comment