+ 1

Why is C# not smart enough to mix data types in an array? I know MAXscript can mix those.

C and need to declare data types

9th May 2018, 4:40 PM
Eelko
Eelko - avatar
9 Respostas
10th May 2018, 12:34 PM
Rabee Abbas
Rabee Abbas - avatar
0
Why do you need to mix data types In an array?
9th May 2018, 4:41 PM
Bagshot
Bagshot - avatar
0
So I can make a list of chars and numbers for example. I have no specific need but was wondering why.
9th May 2018, 4:45 PM
Eelko
Eelko - avatar
0
Is there no way of creating a custom list? Like a list of vars? Not something I 've ever needed to do, but just thinking out aloud. It doesn't sound like it should be impossible, but maybe there is a more accepted, efficient way? I think I really want to know now.
9th May 2018, 4:48 PM
Bagshot
Bagshot - avatar
9th May 2018, 4:57 PM
Bagshot
Bagshot - avatar
0
I'm not familiar with C#, but it's actually really easily done in C, using unions. https://code.sololearn.com/cBz6fjClRd1R/?ref=app Here's the Microsoft documentation on C# unions. Not sure if it helps, as I can't read C#. https://msdn.microsoft.com/en-us/library/bb341731(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
9th May 2018, 5:16 PM
Vlad Serbu
Vlad Serbu - avatar
0
you can use tuples to create a collection of different data types. If you have an uncertain number of variables, you can make a list or array of tuples
9th May 2018, 6:43 PM
hinanawi
hinanawi - avatar
0
Vlad Serbu that isn't the c# equivalent of c unions (iirc no such thing exists), rather a method that adds two enumerable interfaces together
9th May 2018, 6:45 PM
hinanawi
hinanawi - avatar
0
you should use dynamic keyword
10th May 2018, 12:32 PM
Rabee Abbas
Rabee Abbas - avatar