I'm just wondering why we can't just define something like this:
int[] arr = new int[]; arr[0] = 1;
Like the list, to automatically resize. I want to know why this is not possible, and we must set the size each time as follows:
int[] arr = new int[1]; arr[0] = 1;
List<T> resizing is based on creating a new array behind the scenes when necessary.
List<T>
, . , , . , , , - ... , , . ( , .)
- , , , , . , List<T>, , . , , List, ... .
List
, , List<T> - , . " ", .
- , ...
, .
, 100 . 1, 100- . , ?
.
", " - , , . , (C, ++, Java - 1), , , , - .
List<T>, , , , ( , ), .
1.8 # :
- , , . , , , type, ., . , . , . 0 - 1. , , , null .
- , , . , , , type, .
, . , . , . 0 - 1. , , , null .
, , " " - ECMA 334 Spec:
, , , , . , .
1 - #:
# ( "See Sharp" ) - , , - - . # C C, ++ Java .
, , , .
"", List.
. ( ), . .
If you need a collection with dynamic size, there are others, such as the list you talked about.
What you can do is to delay the declaration of the size of the array:
int[] numbers; numbers = new int[10]; numbers = new int[20];
Source: https://habr.com/ru/post/1533496/More articles:Post a WP request through a custom message type that works on the home page but not on the search page - while-loopHow to install a license for images on my site in Google Maps? - microformatsTracing affected lines of code in Visual Studio Debugger - c ++Change display mode in Linux - c ++Save variable value - javascriptHow to mock delegates in moq - unit-testingOverload Prevention on a Remote System Using Parallel.ForEach () - multithreadingFormat specifier for integer variables in format () for EXECUTE? - string-concatenationJavaFX Task Themes Don't End - multithreadingParallel call webservice Foreach - c #All Articles