Skip to content

Instantly share code, notes, and snippets.

@rozer007
Last active November 24, 2021 04:43
Show Gist options
  • Save rozer007/aee918138960b6c531d4b7f763b21de4 to your computer and use it in GitHub Desktop.
Save rozer007/aee918138960b6c531d4b7f763b21de4 to your computer and use it in GitHub Desktop.
Array in C#
Q1) Difference between List and array?
ans Array are static with a fixed size whereas List are dynamic and size can be change according to our need.
Q2) What does split function do?
ans: It convert a string into a array by spliting the string by a character and each word is stores as an element in an array.
Q3) How can we add at the front of a list?
ans: We can use the Insert function to add at index 0.
eg. list.Insert(0,element you want to add).
Q4) Can we iterate the value of the list using foreach loop?
ans: Yes we can iterate the value of list just as we iterate an array.
Q1) What will this statement give :
int[] arr=new int[3];
arr[4]=10;
Console.WriteLine(arr[0]);
a) 0
b) undefined
c) error
d) -1
ans: c) error
Q2) Select the correct output?
int[] arr=new int[6]{1,2,3,4,5,6};
Console.WriteLine(String.Join(",",arr).GetType());
a) Array
b) List
c) String
d) 1,2,3,4,5,6
ans:c) String
Q3) What are the number of elements in its dimenision?
int[,,] arr={{{1,2,0},{3,4,0}},{{0,5,6},{7,0,8}}};
a) 1,2,3
b) 2,3
c) 3,3
d) 2,2,3
ans: d) 2,2,3
Q4) what will be the output?
int[,,] arr={{{1,2,0},{3,4,0}},{{0,5,6},{7,0,8}}};
Console.WriteLine(arr.Length);
a) error
b) 2
c) 3
d) 12
ans: d)12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment