Click here to Skip to main content
15,913,408 members
Home / Discussions / C#
   

C#

 
QuestionAssigning the result of an SQL ExecuteScalar() to an int? Pin
Red_Wizard_Shot_The_Food15-Jan-07 1:42
Red_Wizard_Shot_The_Food15-Jan-07 1:42 
AnswerRe: Assigning the result of an SQL ExecuteScalar() to an int? Pin
Pete O'Hanlon15-Jan-07 1:57
mvePete O'Hanlon15-Jan-07 1:57 
GeneralRe: Assigning the result of an SQL ExecuteScalar() to an int? Pin
aSarafian15-Jan-07 2:30
aSarafian15-Jan-07 2:30 
GeneralRe: Assigning the result of an SQL ExecuteScalar() to an int? Pin
Colin Angus Mackay15-Jan-07 2:48
Colin Angus Mackay15-Jan-07 2:48 
GeneralRe: Assigning the result of an SQL ExecuteScalar() to an int? Pin
aSarafian15-Jan-07 5:04
aSarafian15-Jan-07 5:04 
Questionregular expressions problem Pin
rafiki27015-Jan-07 1:05
rafiki27015-Jan-07 1:05 
AnswerRe: regular expressions problem Pin
Stefan Troschuetz15-Jan-07 3:07
Stefan Troschuetz15-Jan-07 3:07 
QuestionGeneric Dictionary: Dictionary in a Dictionary? Pin
olethroz15-Jan-07 0:33
olethroz15-Jan-07 0:33 
Hi
I was hoping for someone to come out with an idea for a situation i came across..pls bear with me, its a bit long, and i shall explain with code.

this is a sample of my class:

public class Customer<br />
{<br />
  // these are dictionaries of objects and the corresponding IDs<br />
  private Dictionary<long, Membership> membershipDict; //Membership is a class<br />
  private Dictionary<long, Address> addressDict; // Address is a class<br />
<br />
  // methods<br />
  public Membership GetMembershipByKey(long key)<br />
  {<br />
    if (membershipDict.Contains(key))<br />
      return membershipDict[key];<br />
  }<br />
<br />
  public void InsertMembership(Membership membership)<br />
  {<br />
    if (!membershipDict.Contains(key))<br />
        membershipDict.Add(membership.MemberhsipId, membership)<br />
  }<br />
<br />
}<br />

My problem is, I would have lots of methods to just retrieve and insert my Dictionaries of memberships and addresses. And there are more of these dictionaries in my Customer Class. I was thinking of replacing these with Generic Method, for example:

public T GetObjectByKey<T>(long key)<br />
{<br />
  // need some mechanism get the corresponding dictionary, with typeof(T)...but how?<br />
} 


But internally I would need some mechanism to tell me which T is being called. I was thinking of using a Dictionary to keep this info, but its strongly typed, and I cannot use a dictionary to keep a keypair value of Type, and Dictionary<T,K>.

I was thinking of letting my Membership and Address classes inherit from an interface, let's say IModel.

So i would have dictionaries:
private Dictionary<long, IModel> membershipDict;
private Dictionary<long, IModel> addressDict;

so that i can keep a:
Dictionary<System.Type, Dictionary<long, IModel>> typeDict;

but I dont really like this approach. Sorry for the very long explanation, but i hope it explains my dilema. I am looking forward to some great suggestions. Im fairly new with C# and generics. Im just looking for a way to shorten my code. Would hate to have same methods repeating everywhere...Smile | :)

Cheers
AnswerRe: Generic Dictionary: Dictionary in a Dictionary? Pin
aSarafian15-Jan-07 1:12
aSarafian15-Jan-07 1:12 
GeneralRe: Generic Dictionary: Dictionary in a Dictionary? Pin
olethroz15-Jan-07 9:03
olethroz15-Jan-07 9:03 
Questionchoose file dialog box Pin
ALAQUNAIBI14-Jan-07 23:18
ALAQUNAIBI14-Jan-07 23:18 
AnswerRe: choose file dialog box Pin
Christian Graus14-Jan-07 23:45
protectorChristian Graus14-Jan-07 23:45 
Question.net 2.0 - developing webservice Pin
fmardani14-Jan-07 23:17
fmardani14-Jan-07 23:17 
AnswerRe: .net 2.0 - developing webservice Pin
Christian Graus14-Jan-07 23:51
protectorChristian Graus14-Jan-07 23:51 
Questionpassword generation Pin
quiteSmart14-Jan-07 23:05
quiteSmart14-Jan-07 23:05 
AnswerRe: password generation Pin
Russell Jones14-Jan-07 23:10
Russell Jones14-Jan-07 23:10 
GeneralRe: password generation Pin
Muammar©14-Jan-07 23:23
Muammar©14-Jan-07 23:23 
GeneralRe: password generation Pin
Russell Jones14-Jan-07 23:33
Russell Jones14-Jan-07 23:33 
GeneralRe: password generation Pin
quiteSmart14-Jan-07 23:46
quiteSmart14-Jan-07 23:46 
GeneralRe: password generation Pin
Russell Jones14-Jan-07 23:53
Russell Jones14-Jan-07 23:53 
AnswerRe: password generation Pin
V.15-Jan-07 1:18
professionalV.15-Jan-07 1:18 
AnswerRe: password generation Pin
Guffa15-Jan-07 2:06
Guffa15-Jan-07 2:06 
AnswerRe: password generation Pin
szukuro15-Jan-07 2:28
szukuro15-Jan-07 2:28 
GeneralRe: password generation Pin
quiteSmart15-Jan-07 2:45
quiteSmart15-Jan-07 2:45 
GeneralRe: password generation Pin
szukuro15-Jan-07 2:51
szukuro15-Jan-07 2:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.