Professional Documents
Culture Documents
Deshpande
Lecturer, CSE@KLS.GIT
Processing Command-Line
Arguments
Processing Command-Line
Arguments
Processing Command-Line
Arguments
C# Iteration Constructs
for loop
foreach loop
while loop
do.while loop
Decision Constructs
The if/else statement
The switch statement
Enumerations
Enums
Structures
Structures
(methods, properties)
Strings in C#
Strings in C#
Strings in C#
Strings in C#
Strings in C#
Verbatim Strings
Strings in C#
Arrays in C#
An array is a set of data items, accessed using a numerical index
An array is a set of contiguous data points of the same type
Arrays in C#
Array of objects
Multidimensional Arrays
[Declaration
Rectangular ]
int[,] myArray = new int[4,2];
int[,,] myArray = new int [4,2,3];
Initialization
int[,] myArray = new int[,] {{1,2}, {3,4}, {5,6},
{7,8}};
int[,] myArray = {{1,2}, {3,4}, {5,6}, {7,8}};
int[,] myArray;
myArray = new int[,] {{1,2}, {3,4}, {5,6},
{7,8}};
// OK
myArray = {{1,2}, {3,4}, {5,6}, {7,8}};
// Error
Multidimensional Arrays
[ Rectangular ]
Multidimensional Arrays
[ Jagged ]
Multidimensional Arrays
[Initialization
Jagged ]
int[][] myJaggedArray = new int [][] {
new int[] {1,3,5,7,9},
new int[] {0,2,4,6},
new int[] {11,22}
};
int[][] myJaggedArray = {
new int[] {1,3,5,7,9},
new int[] {0,2,4,6},
new int[] {11,22}
};
Multidimensional Arrays
[Initialization
Jagged ]
// Assign 33 to the second element of the first array:
myJaggedArray[0][1] = 33;
// Assign 44 to the second element of the third
array: myJaggedArray[2][1] = 44;
Mixing of arrays
int[][,] myJaggedArray = new int [3][,]
{
new int[,] { {1,3}, {5,7} },
new int[,] { {0,2}, {4,6}, {8,10} },
new int[,] { {11,22}, {99,88}, {0,9} }
};
Multidimensional Arrays
[ Jagged ]
Boxing
Conversion from value type to reference type
int m=100;
object om=m; //creates a box to hold m
int m=100;
object om=(object)m; //c-style casting
int m=10;
object om=m;
m=20;
console.writeline(m); //m=20
console.writeline(om); //om=10
Unboxing
Conversion from reference type to value type
int m=10;
object om=m; //box m
int n=(int)om; //unbox om
int m=500;
object om=m
byte n=(byte)om; // run-time error
Remember: We can only unbox a variable that has previously been
boxed
References
1] Andrew Troelsen, Pro C#with.NET 3.0, SpecialEdition,
Dream tech Press, India, 2007.
2]E. Balagurusamy, Programming in C#, 5thReprint, Tata
McGraw Hill,
2004(For Programming Examples).
3] Tom Archer, Inside C#, WP Publishers, 2001.
4]Herbert Schildt,C#: The Complete Reference, TMH, 2004.
5] Yashavant Kanetkar, C#.NET fundas, First Edition, BPB
Publications,
2002
Contact Me
Email: gcdeshpande@git.edu
gcdeshpande@hotmail.com
Blog: gcdeshpande.spaces.live.com
Follow on twitter:
www.twitter.com/gcdeshpande