Click here to Skip to main content
15,567,466 members
Home / Discussions / C#
   

C#

 
GeneralRe: BSCS FINAL PROJECT Pin
DaveyM696-Sep-10 5:19
professionalDaveyM696-Sep-10 5:19 
GeneralRe: BSCS FINAL PROJECT Pin
Mycroft Holmes6-Sep-10 23:51
professionalMycroft Holmes6-Sep-10 23:51 
QuestionCalendarExtender popup appearing when Enter key is pressed. Pin
dev_asp_shreshtha6-Sep-10 1:48
dev_asp_shreshtha6-Sep-10 1:48 
AnswerRe: CalendarExtender popup appearing when Enter key is pressed. Pin
dan!sh 6-Sep-10 1:59
professional dan!sh 6-Sep-10 1:59 
QuestionNeed help with co/contravariance and generic lists :s Pin
Lee Reid6-Sep-10 0:12
Lee Reid6-Sep-10 0:12 
AnswerRe: Need help with co/contravariance and generic lists :s Pin
Kubajzz6-Sep-10 0:50
Kubajzz6-Sep-10 0:50 
GeneralRe: Need help with co/contravariance and generic lists :s [modified] Pin
Lee Reid6-Sep-10 1:41
Lee Reid6-Sep-10 1:41 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Kubajzz6-Sep-10 2:06
Kubajzz6-Sep-10 2:06 
Lee Reid wrote:
My project has several deriving classes, and values being entirely 'readonly' defeats the purpose of the whole class


I thought you only needed the complete list for iterating through all lists, thus a read-only iterator (such as IEnumerator) could be enough.

IEnumerable(T) can be implemented in a very clean way without the need of any "special programming".
See the following example:

C#
class A {}

class B : A {}

class C : A {}

class MyClass {
  private List<B> listB;
  private List<C> listC;

  public MyClass() {
    // Initialize lists...
  }

  public IEnumerable<A> GetAllItems() {
    // Get each list in this class as IEnumerable<A>
    IEnumerable<A> b = listB;
    IEnumerable<A> c = listC;

    return b.Concat(c);
  }
}


Yes, it is this simple. Note that the GetAllItems method could easily be 1-line long. You can implement some logic to get all the lists in the current class as an array of IEnumerable<A> for easy overriding, it's not more than 1 or 2 very short methods... I don't think this is messy, nor does it require any "special programming" and I highly doubt there is easier and simpler solution.

The one and only question is: does IEnumerable provide enough functionality for your application?
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Lee Reid6-Sep-10 3:02
Lee Reid6-Sep-10 3:02 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Kubajzz6-Sep-10 3:13
Kubajzz6-Sep-10 3:13 
AnswerRe: Need help with co/contravariance and generic lists :s Pin
DaveyM696-Sep-10 1:41
professionalDaveyM696-Sep-10 1:41 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Lee Reid6-Sep-10 2:12
Lee Reid6-Sep-10 2:12 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
DaveyM696-Sep-10 2:31
professionalDaveyM696-Sep-10 2:31 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
DaveyM696-Sep-10 2:54
professionalDaveyM696-Sep-10 2:54 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Lee Reid6-Sep-10 3:08
Lee Reid6-Sep-10 3:08 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
DaveyM696-Sep-10 3:13
professionalDaveyM696-Sep-10 3:13 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Pete O'Hanlon6-Sep-10 4:41
mvaPete O'Hanlon6-Sep-10 4:41 
AnswerRe: Need help with co/contravariance and generic lists :s Pin
PIEBALDconsult6-Sep-10 8:32
professionalPIEBALDconsult6-Sep-10 8:32 
QuestionHow to deploy an Outlook 2003 add-in application(C# and VS 2008)? Pin
milestanley5-Sep-10 23:57
milestanley5-Sep-10 23:57 
QuestionCould use some help please. Pin
pestman5-Sep-10 23:01
pestman5-Sep-10 23:01 
AnswerRe: Could use some help please. Pin
Kubajzz5-Sep-10 23:21
Kubajzz5-Sep-10 23:21 
GeneralRe: Could use some help please. Pin
pestman6-Sep-10 7:27
pestman6-Sep-10 7:27 
GeneralRe: Could use some help please. Pin
Kubajzz6-Sep-10 10:51
Kubajzz6-Sep-10 10:51 
Question"Cannot connect back" - Visual Studio 2008 Remote Debugger for C# apps Pin
Maxwell Chen5-Sep-10 21:19
Maxwell Chen5-Sep-10 21:19 
QuestionQuestion about RegEx Class Pin
Mazdak5-Sep-10 17:24
Mazdak5-Sep-10 17:24 

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.