0
What is wrang?
If account is a class and arr_list is list array , X=0; arry_list ={"hi",111,4.5}; Double V; V=account.arr_list[x+2];
13 RĂ©ponses
+ 1
Almasa Sense
You need to cast it to its original type
string item1 = (string) array_list[0];
int item2 = (int) array_list[1];
double item3 = (double) array_list[2]
+ 4
namespace Sololearn
{
class account{
public static int[] a={"hi",111,4.5};
}
class Program
{
static void Main(string[] args)
{
int x=0;
Double V;
V=account.a[x+2];
}
}
}
+ 2
Almasa Sense
You might want to store the elements in a non-generic collection, such as ArrayList, object[], or List<object>, the first one is not recommended though due to performance issue
Hope this helps đ
+ 2
Calm down, it's just a question
+ 2
Almasa Sense
Ever considered using a Struct or a Class? Then you can store the class objects in an array or a list later on
+ 1
GDSHNIK
Why enum?
+ 1
It's simpler. And you can put ANY of variables
+ 1
And don't call it like only int[] or List<int>()
+ 1
Class
0
What is the other way to get a value from an array?
0
As I understand it, we cannot mix various types of values in array. So { "hi", 111, 4.5 } itself may require extra work/research to accomplish.
0
Just make enumerator, and then you can put variables, and set elements directly or in declaring.
enum a ={Integer=111,str = "Hi", Doublev = 4.5};
0
I work in project to college i have a lot variables to insert like name, age and so on .the project have a 10 tasks so i use list array