You are on page 1of 19

mFirst c# program

mPrinting values
mGeneral form of WriteLine()
mFunction, Class and Namespace
mType of comments.
  


lphabets,Digits,,Sp symbols

Constants,Variables,Keywords

Statements or Instructions

Programs
m  
     
 

   
m   

  


  
  
m 
  
  



 


  
  
  
  
 

 

m  
  
   
  
u   
O
ll variable must be declared.
O +,-,*,/ are
rithmetic Operators
O to perform multiplication be must use * instead of
x.
O For example 2* 3 is correct
O 2 x 3 is wrong.
O 2\3 is not used for division instead of that 2/3 is
used.
O
C# program is nothing but a collection of one or
more namespaces.
O Inside each namespaces there can be multiple classes,
in short namespaces acts as container which can hold
several classes together.
O Each class can contain multiple functions.
O Every single class has to belong to some or the other
namespace.so the outer most container is namespace
inside which a smaller container is a class ,inside
which a smaller container called a function and inside
the function there are variables.
O The namespaces,class,public,static,void all are
keywords.
O C# is case-sensitive and a free form language.
O While defining Main() we have to write
as public static void Main()
m C#, also known as C-Sharp, is a programming language
introduced by Microsoft.
m C# is specially designed to work with the Microsoftǯs .NET
platform.
O Let us understand the structure of a C# program.
Consider the following code example, which defines a class:
public class Hello
{
public static void Main(string[] args)
{
System.Console.WriteLine("Hello, World! \n");
}
}
  M   

[   
u 
 
  
 
 
[   
 
 

 

   


 !"
#
#

M   

[  
˜  
 
  
j   



   

[   
 


 

 

   


 !"
#
#
Accepting and Storing Values in Member Variables

 
   
 
   
 


  
 
  
  
 
   

  

  
 
 $  "   


$  %

  &
' ()

 *  "
„riting and Executing a C# Program

›
  
  

 




 M   
 

m
 

   
 
 



   ,  / , 
 "
 
 
  


  
, %

 *  "
 

 !
 "  
 
 
 

   ,  / 
 "  
./ "

  
 
  

$
-./ %
 
 

  


  &
' ()

 *  "

# 


 
  

++     
 




##
[ 
1[1 
 , "  

 $
-./ " "




  



   &/ , 
 2 3#
++  .  
 
   
, "

0 [ 1 
"

    


 



   &/   
.4/ 

   

 
 
 2 3#$
-./ "
# 
   
#
 M   
  

++  
    / 
 ,5   
$

  
   


 
  
  

[   
 

% 4"
0 [ 1 "
1[1 "
#
#
M
M   M  

m
   
  


 

 


  
 


  
m 

 
  
 

  
  



 

  
  
m 
  
 



 
 




m % &
 


  
 
  


 
m ' 
 



   
ë
˜       &

 ˜  Î

 Î   ë˜  Îë˜  
u Îë ˜     

ë
˜         
 

 

m (   
ë˜     
 
  
  

 
  
 


M
M   M   

m ) 
 
 

   
   
m,5  

m * 


 

 
 

   
  
m,5   5
u 
O In C# semicolon(;) is used to end program
statement.
O For example float p,r,si ;
O ; is known as statement terminator .
O We can write multiple line in single line by using
semicolon.
    u 
O
comment is a line or paragraph of text that will not be
considered as part of your code of a program. There are two
types of comments recognized by C#.
O To display a comment on a line of text, start the line with
two forward slashes //.
nything on the right side of //
would be ignored. Here is an example:
O // This line will be ignored. I can write in it anything I want
The above type of comment is used on only one line. You
can also start a comment with /*. This type of comment
ends with */.
nything between this combination of /* and
*/ would not be read. Therefore, you can use this technique
to span a comment on more than one line.
u  
O
ny number of comments are allowed anywhere in
program.
O
void writing nested comment.