C# Jagged Arrays: An Array of Array - TutorialsTeacher
文章推薦指數: 80 %
A jagged array is an array of array. Jagged arrays store arrays instead of literal values. A jagged array is initialized with two square brackets [][]. The ...
C#
ASP.NETCore
MVC
IoC
TypeScript
Angular
Python
SQLServer
MongoDB
More
✕
.NETTutorials
C#
ASP.NETCore
ASP.NETMVC
IoC
webapi
LINQ
ClientSide
JavaScript
jQuery
Node.js
D3.js
TypeScript
Angular11
AngularJS1
Sass
ServerSide
https
Python
SQL
SQLServer
PostgreSQL
MongoDB
SkillTests
ASP.NETCore
ASP.NETMVC
LINQ
C#
webapi
IoC
TypeScript
AngularJS
Node.js
jQuery
JavaScript
Articles
Tests
LearnC#
C#-GetStarted
C#-VersionHistory
C#-FirstProgram
C#-Keywords
C#-Class
C#-Variable
C#-Implicitly-TypedVariable
C#-DataTypes
Numbers
Strings
DateTime
Structure
Enum
StringBuilder
AnonymousTypes
DynamicTypes
NullableTypes
C#-Value&ReferenceTypes
C#-Interface
C#-Operators
C#-ifelseStatements
C#-TernaryOperator?:
C#-Switch
C#-ForLoop
C#-WhileLoop
C#-Do-whileLoop
C#-PartialClass
C#-Static
C#-Array
MultidimensionalArray
JaggedArray
C#-Indexer
C#-Generics
GenericConstraints
C#-Collections
ArrayList
List
SortedList
Dictionary
Hashtable
Stack
Queue
C#-Tuple
C#-ValueTuple
C#-Built-inExceptions
ExceptionHandling
throw
CustomException
C#-Delegates
FuncDelegate
ActionDelegate
PredicateDelegate
AnonymousMethods
C#-Events
C#-Covariance
C#-ExtensionMethod
C#-StreamI/O
C#-File
C#-FileInfo
C#-ObjectInitializer
C#-UsefulResources
Previous
Next
C#JaggedArrays:AnArrayofArray
Ajaggedarrayisanarrayofarray.Jaggedarraysstorearraysinsteadofliteralvalues.
Ajaggedarrayisinitializedwithtwosquarebrackets[][].Thefirstbracketspecifiesthesizeofanarray,andthesecondbracketspecifiesthedimensionsofthearraywhichisgoingtobestored.
Thefollowingexampledeclaresjaggedarrays.
Example:JaggedArrays
int[][]jArray1=newint[2][];//canincludetwosingle-dimensionalarrays
int[][,]jArray2=newint[3][,];//canincludethreetwo-dimensionalarrays
Intheaboveexample,jArray1canstoreuptotwosingle-dimensionalarrays.jArray2canstoreuptothreetwo-dimensional,arrays[,]specifiesthetwo-dimensionalarray.
Example:JaggedArray
int[][]jArray=newint[2][];
jArray[0]=newint[3]{1,2,3};
jArray[1]=newint[4]{4,5,6,7};
Youcanalsoinitializeajaggedarrayupondeclarationlikethebelow.
Example:JaggedArray
int[][]jArray=newint[2][]{
newint[3]{1,2,3},
newint[4]{4,5,6,7}
};
jArray[0][0];//returns1
jArray[0][1];//returns2
jArray[0][2];//returns3
jArray[1][0];//returns4
jArray[1][1];//returns5
jArray[1][2];//returns6
jArray[1][3];//returns7
Tryit
Youcanaccessajaggedarrayusingtwoforloops,asshownbelow.
Example:JaggedArray
int[][]jArray=newint[2][]{
newint[3]{1,2,3},
newint[4]{4,5,6,7}
};
for(inti=0;i
延伸文章資訊
- 1Jagged Array in Java - GeeksforGeeks
A jagged array is an array of arrays such that member arrays can be of different sizes, i.e., we ...
- 2C# | Jagged Arrays - GeeksforGeeks
- 3Jagged Array in C# - C# Corner
The elements of a jagged array can be of different dimensions and sizes. A jagged array is someti...
- 4不規則陣列- C# 程式設計手冊 - Microsoft Docs
Assign 77 to the second element ([1]) of the first array ([0]): jaggedArray3[0][1] = 77; // Assig...
- 5C# Jagged Array (With Examples) - Programiz
In C#, a jagged array consists of multiple arrays as its element. However, unlike multidimensiona...