Click here to Skip to main content
15,879,613 members
Home / Discussions / C#
   

C#

 
GeneralRe: BSCS FINAL PROJECT Pin
DaveyM696-Sep-10 4:19
professionalDaveyM696-Sep-10 4:19 
GeneralRe: BSCS FINAL PROJECT Pin
Mycroft Holmes6-Sep-10 22:51
professionalMycroft Holmes6-Sep-10 22:51 
QuestionCalendarExtender popup appearing when Enter key is pressed. Pin
dev_asp_shreshtha6-Sep-10 0:48
dev_asp_shreshtha6-Sep-10 0:48 
AnswerRe: CalendarExtender popup appearing when Enter key is pressed. Pin
dan!sh 6-Sep-10 0:59
professional dan!sh 6-Sep-10 0:59 
QuestionNeed help with co/contravariance and generic lists :s Pin
Lee Reid5-Sep-10 23:12
Lee Reid5-Sep-10 23:12 
AnswerRe: Need help with co/contravariance and generic lists :s Pin
Kubajzz5-Sep-10 23:50
Kubajzz5-Sep-10 23:50 
GeneralRe: Need help with co/contravariance and generic lists :s [modified] Pin
Lee Reid6-Sep-10 0:41
Lee Reid6-Sep-10 0:41 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Kubajzz6-Sep-10 1:06
Kubajzz6-Sep-10 1: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 2:02
Lee Reid6-Sep-10 2:02 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Kubajzz6-Sep-10 2:13
Kubajzz6-Sep-10 2:13 
AnswerRe: Need help with co/contravariance and generic lists :s Pin
DaveyM696-Sep-10 0:41
professionalDaveyM696-Sep-10 0:41 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Lee Reid6-Sep-10 1:12
Lee Reid6-Sep-10 1:12 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
DaveyM696-Sep-10 1:31
professionalDaveyM696-Sep-10 1:31 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
DaveyM696-Sep-10 1:54
professionalDaveyM696-Sep-10 1:54 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Lee Reid6-Sep-10 2:08
Lee Reid6-Sep-10 2:08 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
DaveyM696-Sep-10 2:13
professionalDaveyM696-Sep-10 2:13 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Pete O'Hanlon6-Sep-10 3:41
mvePete O'Hanlon6-Sep-10 3:41 
AnswerRe: Need help with co/contravariance and generic lists :s Pin
PIEBALDconsult6-Sep-10 7:32
mvePIEBALDconsult6-Sep-10 7:32 
QuestionHow to deploy an Outlook 2003 add-in application(C# and VS 2008)? Pin
milestanley5-Sep-10 22:57
milestanley5-Sep-10 22:57 
QuestionCould use some help please. Pin
pestman5-Sep-10 22:01
pestman5-Sep-10 22:01 
AnswerRe: Could use some help please. Pin
Kubajzz5-Sep-10 22:21
Kubajzz5-Sep-10 22:21 
GeneralRe: Could use some help please. Pin
pestman6-Sep-10 6:27
pestman6-Sep-10 6:27 
GeneralRe: Could use some help please. Pin
Kubajzz6-Sep-10 9:51
Kubajzz6-Sep-10 9:51 
Question"Cannot connect back" - Visual Studio 2008 Remote Debugger for C# apps Pin
Maxwell Chen5-Sep-10 20:19
Maxwell Chen5-Sep-10 20:19 
QuestionQuestion about RegEx Class Pin
Mazdak5-Sep-10 16:24
Mazdak5-Sep-10 16: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.