Answer Posted / sudhir sheoran
The answer is yes and no.
Ideally array is collection of single data types
E.g :-
array [] arr = new int [10];
it will store only int because datatype is defined
as int in this case.
In case of some particular requirements array can be used
to store diff data types. But in this case array has
to be declared as object array
E.g:-
class Test
{
public static void Main()
{
object[] arr = new object[10];
arr[0] = 1;
arr[1] = "Hello";
Console.WriteLine(arr[0]);
Console.WriteLine(arr[1]);
Console.ReadLine();
}
}
This is successfully complied.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Can arraylist store different data types in c#?
What does question mark mean in c#?
If you define a user defined data type by using the struct keyword, is it a value type or reference type?
User's session is explicitly killed by which method ?
What is .cshtml file?
Explain the use of SN.exe
How do I format in c#?
What is inheritance c#?
What is data hiding in c#?
What is scope c#?
What is the use of tuple in c#?
How long has c# been around?
What is cli in c#?
What is string class in c#?
Okay, so an int is a value type, and a class is a reference type. How can int be derived from object?