Click here to Skip to main content
11,412,182 members (58,565 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
Hi ,

I'm trying to use a dictionary in c# as follows

and seems to be the declaration and initialization are ok .
Then I create an instance of
where Orderstore implements the IStorage and Order implements IEntity.

But when I try to add Orderstore to the dictionary it says "Argument type Orderstore is not assignable to parameter type IStorage"
I wonder anyone can help me with this. Thanks in advance.
Posted 15-Jan-13 19:23pm
Edited 15-Jan-13 23:18pm
Sergey Alexandrovich Kryukov at 16-Jan-13 1:07am
I cannot believe that exception message contains the words "return of the Dictionary", as they make no sense.
It may work out if you show the minimal code sample. Show how you initialize key and value object and add a dictionary element to it.
Suvabrata Roy at 16-Jan-13 4:54am
Please share the order class and some code ...
Sergey Alexandrovich Kryukov at 16-Jan-13 14:10pm
You are right, but better reply to OP's post, not mine. Not a problem though...
Suvabrata Roy at 16-Jan-13 23:26pm
OP's Post mean ...?
Sergey Alexandrovich Kryukov at 16-Jan-13 23:42pm
Oh, sorry for this abbreviation; it's just the jargon we use on this site, which as not very good, as many don't know it. OP means "Original Poster" or "Original Publisher", something like that, in this case, prasadbuddhika.
Suvabrata Roy at 16-Jan-13 23:47pm
Ok, I understand :)

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use the code given below:

Dictionary<type,isynchronizedstorage>> myOrders;

If myOrders is the name of the dictionary, then use

Orderstore order = myOrders[index] as Orderstore;

TypeCast it "as OrderSto0re" then your code will work.


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

  Print Answers RSS
0 OriginalGriff 348
1 Sascha Lefévre 175
2 ProgramFOX 130
3 Maciej Los 110
4 Sergey Alexandrovich Kryukov 105
0 Sergey Alexandrovich Kryukov 8,980
1 OriginalGriff 7,263
2 Maciej Los 3,500
3 Abhinav S 3,248
4 Peter Leow 3,059

Advertise | Privacy | Mobile
Web03 | 2.8.150414.5 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100