Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
int
uint
Byte
Sbyte
short
ushort
long
ulong
=>
=>
=>
=>
=>
=>
=>
=>
Float
Decimal
Double
char
string
bool
var
accordingly
}
if (j == 5)
Console.WriteLine("Not Found");
--------------------------------------------------------int[] a = new int[5];
Console.WriteLine("Enter 5 nos");
for (int i = 0; i <= 4; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
//Foreach loop only works on collections
//Automatically start 0 position, run upto last position &
//increement by 1
Console.WriteLine("Array Values are:-");
foreach (int i in a)
{
Console.WriteLine(i);
}
--------------------------------------------------------static void Main(string[] args)
{
//Array = Continous memory allocations of same type of data
//2-D Array
int[,] a = new int[3, 3];
Console.WriteLine("Enter 9 numbers");
int r,c;
for (r = 0; r <= 2; r++)
{
for (c = 0; c <= 2; c++)
{
a[r,c] = Convert.ToInt32(Console.ReadLine());
}
}
Console.WriteLine("The Values are:");
for (r = 0; r <= 2; r++)
{
for (c = 0; c <= 2; c++)
{
Console.Write(a[r, c]+" ");
}
Console.WriteLine();
}
Console.ReadKey();
}
--------------------------------------------------------------static void Main(string[] args)
{
//Array = Continous memory allocations of same type of data
//Jagged Array -It is an array of arrays of different sizes
int[][] j=new int[3][];
//Defining
j[0] = new
j[1] = new
j[2] = new
int i;
Console.WriteLine("Enter 3 Data in Row1");
for (i = 0; i <= 2; i++)
j[0][i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter 2 Data in Row2");
for (i = 0; i <= 1; i++)
j[1][i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter 4 Data in Row3");
for (i = 0; i <= 3; i++)
j[2][i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Values in Jagged Array");
for (i = 0; i <= 2; i++)
{
int[] a = j[i];
foreach (int k in a)
{
Console.Write(k+" ");
}
Console.WriteLine();
}
}
-------------------------------------------------------------------------------static void Main(string[] args)
{
//String in C#
Console.WriteLine("Enter a String");
String s1 = Console.ReadLine();
Console.WriteLine("Length of the String=" + s1.Length);
Console.WriteLine("String in UpperCase=" + s1.ToUpper());
string s2 = "Hello";
int i = s1.CompareTo(s2);
if (i == 0)
Console.WriteLine("Both Strings are of Same size");
else if (i < 0)
Console.WriteLine("1st String Smaller");
else
Console.WriteLine("2nd string smaller");
if (s1.Equals(s2))
Console.WriteLine("Both strings are same");
else
Console.WriteLine("Both strings are different");
bool r = s1.Contains("H");
if (r == true)
Console.WriteLine("Found");
else
Console.WriteLine("Not Found");
string st = s1.Substring(2, 3);
Console.WriteLine("SubString="+st);