Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Utility is the main class. Here is it possible to combine AvalilableOffers and offersList into a single list?

public class Utility
{
    public List <MainConfiguraion> MainConfig { get; set; }
    public List <UtilityConfiguration> UtilityConfig{ get; set; }         
}

public class MainConfiguraion
{
    public int  Id { get; set; }
    public string EmployeeName { get; set; }
    public List <offerInfo> AvailableOffers { get; set; }

}

public class offerInfo
    {
        public string OfferCode { get; set; } 
        public string OfferName { get; set; }      
        public int OfferId { get; set; }
    }

 public class UtilityConfiguration
    {      
       public  List <balanceList> Points { get; set; }
       public  List <vouchers>   offersList { get; set; }
    }

public class vouchers
    {
        public string voucherID { get; set; }
        public string name { get; set; }
        public string description { get; set; }     
        public string amount { get; set; }       
    }


What I have tried:

I tried using List.Merge . But it is not successfull
Posted
Updated 9-Feb-21 2:39am
Comments
Maciej Los 9-Feb-21 8:38am    
Do not see [AvalilableOffers]...

 
Share this answer
 
v2
Not in a meaningful way, without some form of relationship between them.
As it stands, AvalilableOffers contains offerInfo instances, and offersList contains vouchers; and since both classes are based solely on object and new list that contained both would have to be a List<object> - which makes it complicated to use and makes the string typing that C# is justly proud of useless - every time you took an item out of the collection, you would have to check what type it was and cast it appropriately before you could use it. Your code would become a horrible mess.

The best ways to get this to work would rely on having both the offerInfo and vouchers classes derive from the same base class (or implement an Interface) ... but since they share no common information at all, it's difficult to think of a base class that would allow you to do anything useful with them!

I suspect you need to rethink your data structures with OOPs principles in mind before you go any further with this code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900