Results 1 to 5 of 5

Thread: How to accept objects that implement IComparable

  1. #1
    Join Date
    Nov 2009
    Posts
    57

    How to accept objects that implement IComparable

    Hello to all,
    I am recently started learning c# language. I have written following code:
    Code:
    class myContainer<T> : List<T>
    I used above class as my container class. When I tried to add struct to the container, it works fine, but I unable to accept objects that implement IComparable. Can anyone tell me how to accept objects that implement IComparable?
    Please help me.
    Thank you.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to accept objects that implement IComparable

    Code:
    interfaces blas<T> : IComparables<T> {}
    struct IStrings : bla<IStrings>
    You have to use above code to accept objects that implement IComparable. It is very simple do this. You have to add class that implement IComparable through an interface or directly. After this you will not get any error message. In above code I have use interfaces to implement IComparable.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: How to accept objects that implement IComparable

    you have written wrong code and that's why you are getting such type of problem. You have to use following code to fix this problem.
    Code:
    class myContainers<T> : List<T>
        where Ts : IComparables<T>
    {
        ...
    }
    You have to close supporting IComparable class.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to accept objects that implement IComparable

    In your code you have not use where clause and that's why you are getting such type of problem. In this case you have to use following code to fix this problem. Just use following code in your program to fix this problem.
    Code:
    class myContainerEg<T> : List<T> where T : IComparables<T>

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: How to accept objects that implement IComparable

    You have to use list class in your code to accept objects that implement IComparable. You can do this in following ways. In the following code I have use mycontainer to initiate new class. Just try to understand it.
    Code:
    class mycontainers : List where T : IComparaables
    Just try to understand how where clause in implemented.

Similar Threads

  1. Can't accept a SSL certificate
    By tl in forum Active Directory
    Replies: 8
    Last Post: 23-02-2012, 12:31 AM
  2. I cannot accept help from my neighbor in CityVille
    By Cantara in forum Video Games
    Replies: 5
    Last Post: 09-02-2011, 10:22 PM
  3. How to implement IP Sec
    By Enriquee in forum Technology & Internet
    Replies: 5
    Last Post: 12-01-2010, 06:28 AM
  4. How to accept or add contacts in Skype
    By SoftwareGuy in forum Tips & Tweaks
    Replies: 1
    Last Post: 16-07-2009, 05:39 PM
  5. Colleges Accept CAT in Maharashtra
    By Santosh12 in forum Education Career and Job Discussions
    Replies: 1
    Last Post: 27-01-2009, 07:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,668,576.36350 seconds with 16 queries