C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Play with Arrays in C#


Posted Date: 25 Oct 2007    Resource Type: Code Snippets    Category: Collections

Posted By: Ravi Kumar       Member Level: Silver
Rating:     Points: 10



This code snippet demonstrates usage of a few methods of the Arrays class in C#.



//play with arrays

class playwitharrays
{
static void Main(string[] args)
{
string[] friends = new string[] { "John", "Amy", "Rose", "Lisa", "Alen" };

//display elements of the array
Console.WriteLine("Elements of String array");
foreach (string str in friends)
Console.Write(str+" ");

Console.WriteLine();

Console.WriteLine("Number of elements in the array: " + friends.Length);
Console.WriteLine("This array is a " + friends.Rank + " dimensional array");

//display elements of the array in reverse order
Console.WriteLine("Elements of String array (reverse)");
Array.Reverse(friends);
foreach (string str in friends)
Console.Write(str+" ");

Console.WriteLine();

//display elements of the array in sorted order
Console.WriteLine("Elements of String array (sorted)");
Array.Sort(friends);
foreach (string str in friends)
Console.Write(str+ " ");

Console.ReadKey();

}
}



Output
---------


Elements of String array
John Amy Rose Lisa Alen

Number of elements in the array: 5

This array is a 1 dimensional array

Elements of String array (reverse)
Alen Lisa Rose Amy John

Elements of String array (sorted)
Alen Amy John Lisa Rose



For queries regarding this code write to me - ravi@devsquare.com




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Understanding Arrays  .  Play with Arrays  .  Multidimensional arrays in C#  .  Multidimensional Arrays  .  Arrays in C#  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Export Data from Listview to Excel
Previous Resource: Get Printer Name from a network
Return to Discussion Resource Index
Post New Resource
Category: Collections


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

conference call

Contact Us    Privacy Policy    Terms Of Use