C#.
Net
Type System
• Value Type • Reference Type
Int Class
Char Object
Decimal Array Storing in Heap
Float String Memory
Storing in Byte ………
Stack Memory ……. …….
…. Etc. …. Etc.
User Defined
Structure Data types
Enum
Difference Between Stack Memory and Heap Memory
Stack Memory Heap Memory
int i=10;
int j=i;
String s=“Ram”; s 0040
String s1=s; s1 0040
j 10
i 10 Ram
Memory allocation wise Reference Types are better
Performance wise Value Types are better
Basic Example Of C#
C# C
#include <stdio.h>
#include <conio.h>
main()
{
printf (“C Example “);
getch();
Namespace
System stdio.h Conio.h
Console Classes under namespace printf() getch()
scanf() clrscr()
Write()
Methods under classes
WrilteLine()
Declaring Variables & printing values
C
#include <stdio.h>
#include <conio.h>
main()
{
int Regno=100;
char gender=“M’;
printf (“%d ,%C “, Regno ,gender);
getch();
}
Read the values from user
C# Read and Return the
value type is String
Type casting error
Regno = Convert.ToInt (Console.ReadLine());
Type Conversion
• Implicit Conversion • Explicit Conversion
int i =10; int i =10;
Implicitly i value byte b=i; byte b= (byte) i;
converted into byte Type is mentioned
assigned to b to convert into
byte
Converting any Data Type to String Type Converting any Data Type to any data Type
int TotalMarks=452; string Price="150.00";
string Marks=TotalMarks.ToString(); int Amount=Convert.ToInt32(Price);
Converting any Data Type to integer Type
string Price="150.00";
int Amount=int.Parse(Price);
Type Casting
Example
Boxing & Unboxing
integer i string s byte b
We can store any type
Object obj data into object type
Int i = 10;
Boxing
Object obj;
Obj=i;
Value type implicitly
converted into
Unboxing
Object type is called
Boxing Object type
int k;
Explicitly converted
K=(int) obj into value type is
called Unboxing
Method
Method is nothing but group of statements.
Syntax
<Access Specifiers > <Return Type> <MethodName> (Parameters List)
{
// Statements ; Optional
Example
With out Parameters With Parameters
Public int Add ( ) Public int Add (int x , int y )
{ {
int x , y , z; int z;
z= x +y; z= x + y;
Console.WriteLine(Z); Console.WriteLine(Z);
} }
Method Example
Non Static Method
Static Method