Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Convertir una lista de instancias de clases derivadas como una lista de sus instancias de clases base

Estoy tratando de devolver una lista de clases derivadas (RedThingSets y BlueThingSets) como una lista de su clase base (ThingSets) para que pueda tener una función más genérica devolviéndolas (este es solo un ejemplo para ilustrar).

(Este no es el código real)

 public abstract class ThingSet { public List<Thing> Things; } public class RedThingSet : ThingSet {} public class BlueThingSet : ThingSet {} public void MahClass() { public List<RedThingSet> RedThingsList = new List<RedThingSet>(); public List<BlueThingSet> BlueThingsList = new List<BlueThingSet>(); public List<ThingSet> GetThingSet( bool giveMeTheBlue ) { if ( giveMeTheBlue ) { return BlueThingsList; } else { return RedThingsList; } } }

es posible?

Intenté usar algo as : return BlueThingsList as List<ThingSet>;

Y he intentado emitirlo directamente así: return (List<ThingSet>) BlueThingsList;

Pero tampoco están trabajando,

¿Me estoy acercando a esto completamente mal?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!