×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2013
    Location
    chennai, TN
    Posts
    56

    In Wp7, I'm not able to use a ? extends keyword

    hi

    n Java, I can do the following: (assume Subclass extends Base):

    ArrayList<? extends Base> aList = new ArrayList<Subclass>();
    What is the equivalent in C# .NET? There is no ? extends keyword apparently and this does not work:

    List<Base> aList = new List<Subclass>();

    P.s help me out thanks in advance

  2. #2
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    523

    Re: In Wp7, I'm not able to use a ? extends keyword

    Please check this article if it answers your questions: http://msdn.microsoft.com/en-us/library/d5x73970.aspx

  3. #3
    Registered User
    Join Date
    Dec 2012
    Location
    Zagreb, Croatia
    Posts
    73

    Re: In Wp7, I'm not able to use a ? extends keyword

    Quote Originally Posted by Murugan india View Post
    hi

    n Java, I can do the following: (assume Subclass extends Base):

    ArrayList<? extends Base> aList = new ArrayList<Subclass>();
    What is the equivalent in C# .NET? There is no ? extends keyword apparently and this does not work:

    List<Base> aList = new List<Subclass>();

    P.s help me out thanks in advance
    This is not possible in C#. You can do something else though:
    Code:
    class Base{}
    class Derived : Base{}
    
    List<Base> list = new List<Base>();
    var another = new List<Derived>();
    list.AddRange(another);
    So you can add items to the list if the type of the added item is a subclass of the type contaned in the list.

    This should fit your scenario easily.

Similar Threads

  1. Extends problem!
    By kamoda_pawel in forum Mobile Java General
    Replies: 2
    Last Post: 2007-05-14, 16:32
  2. pushprocess extends midlet
    By rak_eshz in forum Mobile Java General
    Replies: 1
    Last Post: 2006-02-16, 08:40
  3. Error when using extends Canvas.
    By ramis55 in forum Mobile Java General
    Replies: 2
    Last Post: 2005-07-25, 14:58
  4. public class Menu extends MIDlet, Canvas
    By Woody_FX in forum Mobile Java General
    Replies: 4
    Last Post: 2003-12-16, 13:59
  5. MIDlet! mapping Command to a class extends Form
    By enpar in forum Mobile Java General
    Replies: 0
    Last Post: 2003-02-07, 13:18

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×