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 8717655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:21:04+00:00 2026-06-13T06:21:04+00:00

I have these two classes public class BuyEstimateResult { public string SubTitle { get;

  • 0

I have these two classes

public class BuyEstimateResult
{
    public string SubTitle { get; set; }
    public string Value { get; set; }
    public string Formulae { get; set; }
}
public class SellerReportClass
{
    public string Entityname { get; set; }
    public double EntityAmt { get; set; }
    public string Formulae { get; set; }
}

I have to make them such that it should be converted as

public class KeyValue
{
    public string key {get;set;}
    public string value {get;set;}
}

if I pass BuyEstimateResult, its SubTitle should be key and Value should be Value of KeyValue Class and if I pass SellerReportClass then Entityname sould be key and EntityAmt should be Value

any ideas how can it be done

NOTE: I will get List of Both the class

  • 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-13T06:21:05+00:00Added an answer on June 13, 2026 at 6:21 am

    You can use the implicit operator in C# to convert it into a KeyValue like you want – http://msdn.microsoft.com/en-us/library/z5z9kes2(v=vs.110).aspx

    public static implicit operator KeyValue(BuyEstimateResult ber)
    {
         return new KeyValue { Key = ber.SubTitle, Value = ber.Value }
    }
    

    Edit

    To be more specific on how to implement this:

    public class BuyEstimateResult
    {
        public string SubTitle { get; set; }
        public string Value { get; set; }
        public string Formulae { get; set; }
    
        public static implicit operator KeyValue(BuyEstimateResult ber)
        {
            return new KeyValue {Key = ber.SubTitle, Value = ber.Value};
        }
    }
    
    public class SellerReportClass
    {
        public string Entityname { get; set; }
        public double EntityAmt { get; set; }
        public string Formulae { get; set; }
    
        public static implicit operator KeyValue(SellerReportClass sell)
        {
            return new KeyValue { Key = sell.Entityname, Value = sell.EntityAmt.ToString(CultureInfo.InvariantCulture)};
        }
    }
    
    public class KeyValue
    {
        public string Key { get; set; }
        public string Value { get; set; }
    }
    
    public class Program
    {
        static void Main()
        {
            var listB = new List<BuyEstimateResult>
                            {
                                new BuyEstimateResult {SubTitle = "BER1", Value = "BER1_VALUE"},
                                new BuyEstimateResult {SubTitle = "BER2", Value = "BER2_VALUE"}
                            };
    
            var listS = new List<SellerReportClass>
                            {
                                new SellerReportClass {Entityname = "SELL1", EntityAmt = 1.0},
                                new SellerReportClass {Entityname = "SELL2", EntityAmt = 2.5}
                            };
    
            foreach (KeyValue kv in listB)
                Console.WriteLine(kv.Key + ":" + kv.Value);
    
            foreach (KeyValue kv in listS)
                Console.WriteLine(kv.Key + ":" + kv.Value);
        }
    }
    

    To get a single list of KeyValue objects from the two different lists you can do something like this:

    var KeyValueList = listB.ConvertAll(i => (KeyValue) i);
    KeyValueList.AddRange(listS.ConvertAll(i => (KeyValue) i));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes: public class TestClass1 { public int TestInt { get; set;
Say you have these two classes. public class Author { public int ID {get;
I have these two classes public class Person { } public class Company {
Let's say we have these two classes: public class Base { public static int
I have these two classes @DatabaseTable public class User { @DatabaseField(generatedId=true) private int _id;
I have this weird situation. I have these two classes: Public Class Entry End
I have two classes: public class PageMeta { public PageMeta() { } public string
I have these two classes: class Student { String name; String age ; }
I have a problem with these two classes: Creature: public abstract class Creature extends
Suppose I have these two classes class base_size { public: int size() { return

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.