Yes. we can store different/mixed types in a single array by using following two methods: Method 1: using Object array because all types in .net inherit from object type Ex: object[] array=new object[2];array[0]=102;array[1]=”csharp”;Method 2:
Interviews13 answers
Can we store mixed datatypes such as char, string ,int etc. in single array?
13 Answers
Rajeev KumarPosted Mar 20, 2023, 3:07 AM EDT
Yes
Hovhannes MovsisyanPosted Feb 28, 2020, 4:05 AM EST
Yes
Hovhannes MovsisyanPosted Feb 28, 2020, 4:05 AM EST
array it wont possible
Bidyasagar MishraPosted Aug 4, 2019, 4:35 PM EDT
yes
Kaushik DudhatPosted Feb 13, 2019, 1:28 AM EST
Yes you can use ArrayList Collection which is Type Independent
MelbinPosted Oct 7, 2018, 5:56 AM EDT
We can do that but , ArrayList is the correct way to do that.
Ayappan AlagesanPosted Jul 31, 2018, 12:16 AM EDT
In single array we can't store mixed datatype however by using ArrayList you can achieve this
Chandan PrasadPosted Jul 27, 2018, 9:18 AM EDT
using ArrayList we can do that
Udit ChauhanPosted Jul 18, 2018, 12:05 AM EDT
Yes we can store different/mixed types in a single array by using following two methods:
Method 1: using Object array because all types in .net inherit from object type
Ex: object[] array=new object[2];
array[0]=102;
array[1]="csharp";
Method 2: Alternatively we can use ArrayList class present in System.Collections namespace .We can use Add() method of ArrayList class to add different data types to the ArrayList collection.
Ex: ArrayList arrlist=new ArrayList();
arrlist.Add(98);
arrlist.Add("Dotnet");
Samita SahuPosted Jul 5, 2018, 8:36 PM EDT
You can do the same by many ways one of them is using a union:
union {
int ival;
float fval;
void *pval;
} array[10];
You will have to keep track of the type of each element, though.
You can try it via Class also.
Shivam ShuklaPosted Jun 27, 2018, 5:02 AM EDT
Yes, We can use mixed datatypes in a single array.
struct {
enum { is_int, is_float, is_char } type;
union {
int ival;
float fval;
char cval;
} val;
} my_array[10];
Kalyani ShevalePosted Jun 25, 2018, 9:44 PM EDT
Yes, We can do.
class Example {
public string Name {get; set;}
public int Age {get; set;}
}
//Method
{
object[] MyArray = new object[3];
MyArray[0] = "Faisal";
MyArray[1] = 100;
Example exp = new Example();
exp.Name = "Faisal Pathan";
exp.Age = 22;
MyArray[2] = exp;
}
Faisal PathanPosted Jun 6, 2018, 9:34 AM EDT







