Muthu karthikeyan,Madurai
Basic structure of c sharp program.
using System;
class Welcome
static void Main(string[] args)
{
Console.WriteLine("hai
suresh");
}
}
First line System is a namespace. it contains library class
which contain codings to be executed . here understand that namespace is collection
of classes..
Next we declared the class named welciome.in c# every thing
must be(method,interfacr,properties etc) inside the class like java.
Console is a library class which contains methods to get
input and write output. Here we used WriteLine method to print output.
if we removed the firstline
then the coding to print the output will be
System.Console.WriteLine("hai
suresh");
it will be good until you used only one use of Console
class. But if you have multiple lines of code using Console class Then using
System declaration will be good.
Next one interactive program.
using System;
namespace ConsoleApplication2
{
class Program
{
{
Console.WriteLine("enter
your tamil mark");
String mark = Console.ReadLine();
int Tmark = Int32.Parse(mark);
Console.WriteLine("Tamil
mark=" +Tmark);
}
}
}
mark is the variable which will be of string typewe have to
convert it into int by using
Int32.Parse.
printing output by WriteLine may also be done by using place holders.
for example
Console.WriteLine("tamil mark={0}",Tmark);
if you have 2 outputs then
Console.WriteLine("tamil mark={0}, English mark={1}”,Tmark,Emark);
The place holders like {0},{1} will be replaced by the data contained
by the variables in Tmark, Emrk etc
to be continued
No comments:
Post a Comment