Can you store multiple data types in System.Array?
Answers were Sorted based on User's Feedback
Answer / naveen
Bit tricky answer. Convert into system.object and store
(using boxing)like this you are able to store differnt
types which is not recommended
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / guest,naveen
You can try it in your System, by writing a small program.
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / joe
Yes and no. Yes you can but it is no longer an array. You
would want to use a Structure. In a way, structures are
better arrays. Look 'em up, they are very handy.
| Is This Answer Correct ? | 0 Yes | 0 No |
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 |
What is for loop in c#?
Does C# supports multi-dimensional arrays?
What is cosole application?
in the nunit test framework, which attribute must adorn a test class in order for it to be picked up by the nunit gui?
What?s the .NET datatype that allows the retrieval of data by a unique key?
Explain hash table in c# ?
What is static and use of it?
Explain the use of SN.exe
What is attribute and reflection in c#?
What is the base class of all classes in c#?
Which layer executed first among these Application layer,Buisness layer or Data Base Layer?
What is an assembly qualified name? Is it a filename? How is it different?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)