You can't define C#.net arrays with an infinite array length. You must have to provide a length for the array. But there is a solution to fulfill the need of infinite arrays in C#.net.
We call it as List.
We can define a C#.net array like below,
Syntax:-
List<data_type>name_for_list=new List<data_type>();
eg:-
List<char>plainChar=new List<char>();
We can feed data to the list like below,
Syntax:-
list_name.Add(value_needed_to_add);
eg :-
plainChar.Add('C');
We can retrieve elements from the list like below,
Syntax:-
list_name[index_of_the_element];
eg:-
plainChar[3];
No comments:
Post a Comment