Advertisement

09.20.2008 at 05:04AM PDT, ID: 23748127
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

C# .NET Key to Object mapping where the key is a member of the object

Asked by XPUSR in Software/Systems Design, C# Programming Language, Design Patterns

Tags:

C# .NET Key to Object mapping where the key is a member of the object


Hi experts,

I have the following objects which act to store a list of account values. Each Account has a unique AccountId(which has a contryId and numericId) and a collection of AccountValues(which is just a decimal value for any one of the AccountValue enumerations - see code snippet below).

I need to store a collection of Accounts that can be be efficiently indexed using the AccountId(perhaps as a string using the ToString() overload - see AccountId.ToString() in the code snippet ) as the key.

I had originally wrote my code to store the Accounts as a collection i.e. List<Account> and used the account.Find(compareAccountId) method with a compareAccountId predicate to find a specific Account however my list of account objects is quite large so I would really like to use a Hashtable collection, such as NameValueCOllection to increase the speed of access i.e. to index rather than find.

This would take the form:

NameValueCollection<string AccountId, Account> accountAtAccountId

I would use the AccountId.ToString() method to retrive a string representation of the AccountId for the collection Key.

However, I don't believe this to be a good design choice because I am storing the AccountId in two places: 1) as the Key part of the collection and 2) in the Account Object itself.

This is not ideal as we have dublicate data and a change in the Account.AccountId could lead to a senario where the accountAtAccountId key could read "USA123456" however the Account stored at this index could have a  Account.AccountId that after an update could read some completely different AccountId such as "UK3435432".

I don't want to move the AccountId out of the Account data type as this would leave the Account as an Account without an identifier.

Perhaps I could store some form of a reference to the AccountId as the Key in the NameValueCollection.
 
Appreciate any suggestions?

Thanks,
jStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
struct Account
{
  public AccountId accountId;
  public List<AccountValue> accountStatistics = new List<AccountValue>;
  
  public Account(AccountId accountId)
  {
    this.accountId = accountId;
    
  }
}
 
 
// We have an Account Id stored as a struct
struct AccountId
{
  public string countryId
  public int numericId
 
  public AccountId(string countryId, int numericId)
  {
     this.countryId = countryId;
     this.numbericId = numericId;
  } 
 
  // overload the the ToString() method to return a composite of the Id
  public override ToString()
  {
    return countryId + numericId.ToString();
  }
}
 
struct AccountValue
{
   public decimal value;
 
   //defalut to one year turnover  
   public AccountValueType type = AccountValueType.OneYearTurnover;
     
   public AccountValue(AccountValueType type, decimal value)
   {
     this.type = type;
     this.value = value;
   }
}
 
enum AccountValueType
{
  OneYearTurnover = 0,
  TwoYearTurnover,
  ThreeYearTurnover,
  TaxReturns
}
 
Loading Advertisement...
 
[+][-]09.20.2008 at 11:35AM PDT, ID: 22531019

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Software/Systems Design, C# Programming Language, Design Patterns
Tags: C# .NET
Sign Up Now!
Solution Provided By: CyrexCore2k
Participating Experts: 2
Solution Grade: A
 
 
[+][-]09.26.2008 at 05:49AM PDT, ID: 22578893

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.26.2008 at 06:55AM PDT, ID: 22579500

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10.01.2008 at 02:45PM PDT, ID: 22619426

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.01.2008 at 03:52PM PDT, ID: 22619872

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.02.2008 at 03:23AM PDT, ID: 22622656

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.02.2008 at 11:49PM PDT, ID: 22631596

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.02.2008 at 11:57PM PDT, ID: 22631632

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.29.2008 at 08:20AM PDT, ID: 22832099

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]11.02.2008 at 06:29AM PST, ID: 22861646

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628