I am using C# asp.net in my project. I use 2d array in that. Named roomno. When I try to remove one row in that. So I Convert the array into list.
static string[,] roomno = new string[100, 14];
List<string>[,] lst = new List<string>[100, 14];
lst = roomno.Cast<string>[,]().ToList();
Error 1 Invalid expression term 'string' in this line...
if i try below code,
lst = roomno.Cast<string>().ToList();
I got
Error 3 Cannot implicitly convert type 'System.Collections.Generic.List<string>' to 'System.Collections.Generic.List<string>[*,*]'
lst = roomno.Cast().ToList();
What is the Mistake in my code?.
After that, I plan to remove the row in list, lst.RemoveAt(array_qty);
This:
is declaring a 2-D array of
List<string>values.This:
… simply doesn’t make sense due to the position of the
[,]between the type argument and the()for the method invocation. If you changed it to:then it would be creating a
List<string[,]>but it’s still not the same as aList<string>[,].Additionally,
roomnois just a 2-D array of strings – which is actually a single sequence of strings as far as LINQ is concerned – so why are you trying to convert it into an essentially 3-dimensional type?It’s not clear what you’re trying to do or why you’re trying to do it, but hopefully this at least helps to explain why it’s not working…
To be honest, I would try to avoid mixing 2-D arrays and lists within the same type. Would having another custom type help?
EDIT: LINQ isn’t going to be much use with a 2-D array. It’s designed for single sequences really. I suspect you’ll need to do it “manually” – here’s a short but complete program as an example: