Click here to Skip to main content
Sign Up to vote bad
good
See more: C#
Hi ,

I'm trying to use a dictionary in c# as follows
 
Dictionary<Type,IStorage<IEntity>>
and seems to be the declaration and initialization are ok .
Then I create an instance of
Orderstore:IStorage<Order>
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 - 18:23
Edited 15 Jan '13 - 22:18

Comments
Sergey Alexandrovich Kryukov - 16 Jan '13 - 1:07
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. —SA
Suvabrata Roy - 16 Jan '13 - 4:54
Please share the order class and some code ...
Sergey Alexandrovich Kryukov - 16 Jan '13 - 14:10
You are right, but better reply to OP's post, not mine. Not a problem though... —SA
Suvabrata Roy - 16 Jan '13 - 23:26
OP's Post mean ...?
Sergey Alexandrovich Kryukov - 16 Jan '13 - 23:42
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. —SA
Suvabrata Roy - 16 Jan '13 - 23:47
Ok, I understand :)

1 solution

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.
 
Regards.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 253
1 Rohan Leuva 220
2 Sergey Alexandrovich Kryukov 208
3 Abhinav S 168
4 Mahesh Bailwal 165
0 Sergey Alexandrovich Kryukov 8,494
1 OriginalGriff 6,799
2 CPallini 3,603
3 Rohan Leuva 2,923
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid