In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "example Analysis of C # Array Operation". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought slowly and deeply. Let's study and learn "C # array operation example analysis"!
An array is a collection of objects of the same type. Because arrays can be of almost any length, you can use arrays to store thousands or even millions of objects, but you must determine the size of the array when you create it. Each item in the array is accessed by index, which is a number indicating where or where the object is stored in the array. Arrays can be used to store both reference types and value types.
C # array operation program:
Using System
Using System.Collections.Generic
Using System.Text
Namespace ClassAboutArray
{
Public class CreateArray
{
/ / /
/ / definition of one-dimensional array
/ / /
Public void testArr1 ()
{
Int [] myIntArr = new int [100]
/ / define an int array with a length of 100
String [] mystringArr = new string [100]
/ / define a string array with a length of 100
Object [] myObjectArr = new object [100]
/ / define an int array with a length of 100
Int [] myIntArr2 = new int [] {1,2,3}
/ / define an int array of length 3
String [] mystringArr2 = new string [] {"oil", "salt"}
/ / define a string array of length 2
}
/ / /
/ / definition of multidimensional array
/ / /
Public void testArr2 ()
{
Int [,] myIntArr = new int [10,100]
/ / define a two-dimensional int array of 10 to 100
String [,] mystringArr = new string [2,2,3]
/ / define a 3-D string array of 2'2'3
Int [,] myIntArr2 = new int [,] {{1,2,3}, {- 1,-2,-3}}
/ / define a two-dimensional int array of 2x3 and initialize the
String [,] mystringArr2 = new string [,] {{"oil", "salt"}, {"besieged fortress", "morning dew"}}
/ / define a two-dimensional string array of 2x2 and initialize the
}
/ / /
/ / definition of staggered array
/ / /
Public void testArr3 ()
{
Int [] [] myJaggedArray = new int [3] []
MyJaggedArray [0] = new int [5]
MyJaggedArray [1] = new int [4]
MyJaggedArray [2] = new int [2]
Int [] myJaggedArray2 = new int [] []
{
New int [] {1,3,5,7,9}
New int [] {0,2,4,6}
New int [] {11,22}
}
}
}
Public class TraverseArray
{
/ / /
/ / use GetLowerBound | GetUpperBound to traverse the array
/ / /
Public void test1 ()
{
/ / define two-dimensional array
String [,] myStrArr2 = new string [,]
{{"oil", "salt"}, {"besieged city", "morning dew"}, {"hairy bear", "Snoopy"}}
/ / Loop output
For (int I = myStrArr2.GetLowerBound (0); I 3-> 2-> 1->
Console.WriteLine ("original array:")
For (int I = 0; I 2-> 3-> 4-> 5->
Console.WriteLine ("sort the following array:")
For (int I = 0; I Li Si (4)-> Wang Wu (3)-> pockmarked (2)-> naughty (1)->
Console.WriteLine ("original array:")
For (int I = 0; I pockmarked (2)-> Wang Wu (3)-> Li Si (4)-> Zhang San (5)
Console.WriteLine ("sort the following array:")
For (int I = 0; I 4-> 3-> 2-> 1->
Console.WriteLine ("original array:")
For (int I = 0; I 2-> 3-> 4-> 5->
Console.WriteLine ("reverse subsequent array:")
For (int I = 0; I 4-> 3-> 2-> 1->
Console.WriteLine ("original array:")
For (int I = 0; I 4-> 3->
Console.WriteLine ("copy array:")
For (int I = 0; I 4-> 3-> 2-> 1->
Console.WriteLine ("original array:")
For (int I = 0; I 0-> 5-> 4-> 3-> 2-> 1->
Console.WriteLine ("copy array:")
For (int I = 0; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.