Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi!
I want to store array in hash table EX:


array [,] m = new array(){"doucument",13.4};
hashtable h = new hashtable();
h.add(1,m );
);

please help me Error:
A nested array initializer is expected in line 1

"array [,] m = new array(){"doucument",13.4}"
Posted
Updated 25-Nov-11 6:40am
v2
Comments
BillWoodruff 25-Nov-11 13:13pm    
This question voted #1 because it's an exact dupicate of the same question you posted a few hours before this one at: http://www.codeproject.com/Questions/290065/how-store-in-hash-table-in-csharp.

Richard MacCutchan shows you how to achieve this below, but I want to comment that your code is so confused (and you omit the required upper-case names for .NET keywords), that you really need to get a good basic book on C#, and study what Arrays are, and how they are used. What HashTables are, and how both these data-structures that have been with us since the beginnings of .NET are now often valuably replaced with newer data-strucures like ArrayList, generic Lists, Dictionaries, Tuples, etc.
LanFanNinja 25-Nov-11 13:18pm    
I agree.
Sergey Alexandrovich Kryukov 25-Nov-11 17:39pm    
Agree!
--SA
Richard MacCutchan 26-Nov-11 4:07am    
Agree 100% Bill.

1 solution

Try
C#
Object[] m = { "doucument", 13.4 };
System.Collections.Hashtable h = new System.Collections.Hashtable();
h.Add(1, m);
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Nov-11 21:56pm    
And why?
Please see my solution: http://www.codeproject.com/Answers/290254/how-store-in-hash-table-in-csharp#answer3
(yes, this is shameless repost).
Don't you see that the OS's attempts are beyond repair; and your formally valid sample won't help because OP apparently does not understand anything about what she/he is doing?
--SA
Richard MacCutchan 26-Nov-11 4:06am    
Yes, I did wonder about that, but we get so many code snippets added to questions by people who do not know how copy and paste works that I just assumed it was hurried typing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900