If all the fields are required, then they are required. Using a dictionary can only add overhead and incur extra memory costs. A dictionary approach may be useful in a few specific scenarios, such as property bag implementations, and sparse event handlers (since events are the most obvious sparse data).
If the fields are used sparsely (i.e. often not more than a few are in use), then perhaps push the related fields into a number of inner classes (per group of related fields) - i.e. instead of:
class Foo {
string userName;
int userId;
string orderReference;
DateTime orderDate;
...
}
something like:
class Foo {
class UserInfo { // move this outside if it makes sense to re-use it
public int Name {get;set;}
public int Id {get;set;}
}
UserInfo user;
class OrderInfo { // move this outside if it makes sense to re-use it
public string Reference {get;set;}
public string Date {get;set;}
}
OrderInfo order;
}
Then when you have to store the user data, create a new UserInfo
; if you don't need the user data, leave user
null.