Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7816511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:53:37+00:00 2026-06-02T05:53:37+00:00

I have managed to create my own IList sub class using some code i

  • 0

I have managed to create my own IList sub class using some code i found on another thread on the MSDN. I have added some of my own methods and have tested the class in basic scenarios and it seems to be working fine.

The problem is that when i try and use the regular .ToList() method i am returned a List instead of my custom pList. Obviously i need to cast it to my new type but i am unsure how. Do i need to implement another method in my custom iList to allow it to be assigned with a different format?

My class is declared as shown below.

public class pList<T> : IList<T>

James

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:53:38+00:00Added an answer on June 2, 2026 at 5:53 am

    You won’t be able to cast a List<T> directly to pList<T>. You could make an extension method (just like ToList). Assuming your class has a constructor that takes an IEnumerable<T> to populate the list:

    static class EnumerableExtensions
    {
        static pList<T> ToPList<T>(this IEnumerable<T> sequence) { return new pList<T>(sequence); }
    }
    

    If your class doesn’t have such a constructor, you can either add one, or do something like this:

    static class EnumerableExtensions
    {
        static pList<T> ToPList<T>(this IEnumerable<T> sequence)
        {
            var result = new pList<T>();
            foreach (var item in sequence)
                result.Add(item);
            return result;
        }
    }
    

    my pList class does have a constructor that takes IEnumerable have added your extension method but i am still unable to see ToPList() within the List Am i missing something?

    First, if you have such a constructor, and you want to convert an existing List<T> to a pList<T>, you can of course do this:

    List<T> originalList = GetTheListSomehow();
    var newList = new pList<T>(originalList);
    

    To use an extension method, you have to make sure that the method is in scope. I didn’t add access modifiers to my example. Put internal or public in, as appropriate:

    public static class EnumerableExtensions
    {
        internal static pList<T> ToPList<T> //...
    

    Also, if you want to use the extension method in a different namespace, you’ll have to have a using directive in scope. For example:

    namespace A { public static class EnumerableExtensions { ...
    

    Elsewhere:

    using A;
    // here you can use the extension method
    
    namespace B
    {
        public class C
        {
            ...
    

    or

    namespace B
    {
        using A;
        // here you can use the extension method
    
        public class C
        {
            ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have managed to create a custom action in C# using MakeSfxCA which is
I have been using jfreechart to create Gantt chart and even managed to add
I have managed to create a simple app which deletes (bypassing the recycle bin)
I have created some documents and managed to make some simple queries but I
I've a must to create wcf service with parameter. I'm following this http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/8f18aed8-8e34-48ea-b8be-6c29ac3b4f41 First
I have make a little Extension for Magento 1.6.2. I managed to write code
Hi I am hoping for some advice. I have just managed to get a
if i'm using .net dll from delphi code, by exporting types, will managed code
I have started using Assistly for managed customer support (incredible by the way if
As a direct result of my own stupidity I have managed to somehow get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.