Academic Tutorials



English | French | Portugese | German | Italian
Google

Home Source Codes E-Books Downloads Contact Us About Us

C# : C Sharp
Introduction to .NET
An Introduction To The .NET Framework
System Requirements
Application Types in C#
To Begin With C# Programming
.NET Type
Predefined Reference Types
Data types in C# and .NET
Classes and Object Model in .NET
Property in C# class
Arrays
Method Overloading
C# Tutorial Namespaces
Interfaces
Delegates in C#
Events in C#
Reflection
Exception Handling

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
AJAX Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PHP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
.NET (dotnet)
Microsoft.Net
XML Web Services
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills


Arrays

Previous Next



Arrays

C# arrays are reference types. The size of the array is not part of the array type

int[] row;
int[,] grid;

Array instances are created using the new keyword. Array elements are default initialised to zero (enums and numeric types), false (bool), or null (reference types).

row = new int[42];
grid = new int[9,6];

Array instances can be initialised:

int[] row = new int[4]{ 1, 2, 3, 4 }; // longhand
int[] row = { 1, 2, 3, 4 }; // shorthand
row = new int[4]{ 1, 2, 3, 4 }; // okay
row = { 1, 2, 3, 4 }; // compile time error

Array indexes start at zero and all array accesses are bounds checked (IndexOutOfRangeException). All arrays implicitly inherit from the System.Array class. This class brings array types into the CLR and provides some handy properties and methods:

namespace System
{
public abstract class Array : .
.. {
...
public int Length { get { ... } }
public int Rank { get { ... } }
public int GetLength(int rank) { ... }
public virutal IEnumerator GetEnumerator() { ... }
...
}
}



What are Jagged Arrays in C#?

A special type of array is introduced in C#. A Jagged Array is an array of an array in which the length of each array index can differ.

Example: A Jagged Array can be used is to create a table in which the lengths of the rows are not same. This Array is declared using square brackets ( [ ] ) to indicate each dimension.

The following code demonstrates the creation of a two-dimensional jagged array.

Class Jagged
{
public static void Main()
{
int [][] jagged=new int [3][];
jagged[0]=mew int[4]
jagged[1]=mew int[3]
jagged[2]=mew int[5]
int I;
‘Storing values in first array
for (I=0;I<4;I++)
jagged[0][I]=I;
‘Storing values in second array

for( I=0;I<3;I++)
jagged[1][I]=I;
‘Storing values in third array

for(I=0;I<5;I++)
jagged[2][I]=I;
‘Displaying values from first array

for (I=0;I<4;I++)
Console.WriteLine(jagged[0][I])
‘Displaying values from second array
for (I=0;I<3;I++)
Console.WriteLine(jagged[1][I])

‘Displaying values from third array
for(I=0;I<5;I++)
Console.WriteLine(jagged[2][I])

}
}

The element type of an array cans itself be an array creating a so-called “ragged” array. Ragged arrays are not CLS compliant. We can use a foreach statement to iterate through a ragged array or through a rectangular array of any rank:

class ArrayIteration
{
static void Main()
{
int[] row = { 1, 2, 3, 4 };
foreach (int number in row) {
...
}
int[,] grid = { { 1, 2 }, { 3, 4 } };
foreach (int number in grid) {
...
}
int[][] ragged =
{ new int[2]{1,2}, new int[4]{3,4,5,6} };
foreach (int[] array in ragged) {
foreach (int number in array) {
...
}
}
}
}



Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previous Next

Keywords c# passing arrays, c# multidimensional, c# two dimensional array, c# multi dimensional arrays, c# multidimensional array, c# array, array in c#, c# string array, arrays c#, arrays in c#, byte array c#, string array in c#, c# dynamic array, c# char array, string to byte array c#, c# array sort, c# array, c# declare array, c# array declaration, c# initialize array, array to string c#, c# convert byte array


HTML Quizes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
XML Quizes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizes
JavaScript Quiz
VBScript Quiz
AJAX Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizes
ASP Quiz
PHP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
.NET (dotnet) Quizes
Microsoft.Net Quiz
XML Web Services Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
Multimedia Quizes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Web Building  Quizes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Java Quizes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Programming Langauges Quizes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Soft Skills Quizes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz

Privacy Policy
Copyright © 2003-2008 Vyom Technosoft Pvt. Ltd., All Rights Reserved.