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

  • Home
  • SEARCH
  • 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 7811581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:13:01+00:00 2026-06-02T04:13:01+00:00

I will start with code class LocData { public virtual TypeA Copy () {

  • 0

I will start with code

class LocData 
{
    public virtual TypeA Copy () { ... }
    ...
}

class LocDataCollection<T> : List<T> where T: LocData
{
    public LocDataCollection<T> Copy() 
    {
        LocDataCollection<T> locDatas = new LocDataCollection<T>();
        foreach (T locData in this)
        {
            T locData2 = locData.Copy() as T;
            locDatas.Add(locData2);
        }
        return locDatas;
    }
  ...
}

and

class TypeA : LocData
{
  public new TypeA Copy () { ... }
  ...
}

class TypeACollection : LocDataCollection<TypeA>
{
}

test code:

TypeACollection typeAs = new TypeACollection();
...
TypeACollection typeAs2 = typeAs.Copy();

compile message:

“Cannot implicitly convert type ‘LocDataCollection’ to ‘TypeACollection’. An explicit conversion exists (are you missing a cast?)”

I have to change to

TypeACollection typeAs2 = typeAs.Copy() as TypeACollection;

compile pass but at run time error out. typeAs2 return as null even typeAs is not null.

  • 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-02T04:13:06+00:00Added an answer on June 2, 2026 at 4:13 am

    typeAs.Copy() returns a LocDataCollection<TypeA>. But you cannot assign one of those to a TypeACollection because TypeACollection is more derived than LocDataCollection<TypeA>.

    You could perhaps solve the problem by making your copy method receive a LocDataCollection<T>:

    class LocDataCollection<T> : List<T> where T: LocData
    {
        public void CopyTo(LocDataCollection<T> dest) 
        {
            ....
        }
    }
    

    and then at the call site:

    TypeACollection typeAs = new TypeACollection();
    TypeACollection typeAs2 = new TypeACollection();
    typeAs.CopyTo(typeAs2);
    

    Of course, this won’t copy any of the TypeACollection specific stuff, unless you added an override to that effect.

    But I don’t really know enough about your problem to be confident that this is an appropriate solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I will start by explaining my scenario in code: public class A { }
This is my ListActivity after clicking on the list it will start a new
I have developed a code that will start two threads upon executing public class
I have some code that will be accessed from two threads: class Timer{ public:
Consider the code: class UPDServer { //start listener public void start() { UdpClient listener
I will start new PDA project on the windows mobile and compact framework 2.0
As we all know Java program will start executing from the public static void
I have an application and every new created activity will start an async task
I'm new in Obj C programming, so i will start from beginning I have
How does async JMS work? I've below sample code: public class JmsAdapter implements MessageListener,

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.