hi,

I need to copy a dictionary to another dictionary where the Dictionary contains class data as value for eg I want to copy the data of object A1 to A2 .Thanks for your time.

Class A
{
}
Class B
{
}
Main()
{

Dictionary<int,A> A1 = new Dictionary<int,A>(); // first dictionary obj
Dictionary<int,B> A2 = new Dictionary<int,B>(); // Second dictionary obj

}

What are you trying to accomplish? You need to provide more detail, such as some variable names and data types to make it easier to see what you are trying to accomplish.

Obviously, there would be no point to doing the following:

public class A
{
    public string firstName = string.Empty;
    public string lastName = string.Empty;
}//A

public class B
{
    public string firstName = string.Empty;
    public string lastName = string.Empty;
}//B

However, at times, inheritance may be of use:

public class A
{
    public string firstName = string.Empty;
    public string lastName = string.Empty;
}//A

public class B : A
{
    public string streetName = string.Empty;
    public string zipCode = string.Empty;
}//B
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.