I need to create several 2D arrays of mixed datatypes in C#. The arrays are actually coming from a database and I need to be able to store that data in 2D arrays that will take mixed datatypes. I saw a similar question here: Defining two dimensional Dynamic Array with different types, and tried what was suggested by creating a class of the datatypes I'll be using for the project and creating an array of the class I made but doing so gave me errors.
Errors :
CS0029 Cannot implicitly convert type 'Client.Aggregate.Arrays' to 'int'
CS0029 Cannot implicitly convert type 'Client.Aggregate.Arrays' to 'System.DateTime'
CS0029 Cannot implicitly convert type 'Client.Aggregate.Arrays' to 'string'
and the vice versa:
CS0029 Cannot implicitly convert type 'int' to 'Client.Aggregate.Arrays'
CS0029 Cannot implicitly convert type 'System.DateTime' to 'Client.Aggregate.Arrays'
and so on...
public class Arrays {
public string String { get; set; }
public char C { get; set; }
public int Int { get; set; }
public double Double { get; set; }
public DateTime DateTime { get; set; }
}
void Calculation(Arrays[,] SupArray, Arrays[,] Source)
{
DateTime ValidDate = Source[2, 2];
string LineName = SupArray[4, 10];
string LineModel = SupArray[6, 71];
//Here's some sample code you can use to test/see the other errors I'm getting.
//It throws an error whether I go from standard data type to Arrays or Arrays to standard data type.
Arrays[,] DArray = new Arrays[50, 50];
DArray[1, 3] = "DMG";
DArray[1, 2] = "Y";
DArray[1, 4] = 4126;
DArray[1, 1] = new DateTime(2019, 12, 30);
}
//This is a simplified version of my code. I have quite a few arrays I need to make
//capable of storing mixed data types so ideally solutions should be around
//how to do this with arrays (not lists or dictionaries) as arrays are the only thing
//that really works for my project.