How do I Create New instance of an Object?

Posted on 2009-04-27
Last Modified: 2013-12-17
Im using Visual Studio 2008 and programming a windows application using Visual C#

I think this should be easy. Ive a variable called george as follows;

List<int> george;

George contains a list of integers.

I want to create a copy of george and call it bob. How Do I do this?

Ive dont this so far.

List<int> bob = new List<int>

How do i copy the contents of george to bob?
Question by:rangers99
    LVL 16

    Accepted Solution

    List<int> bob = new List<int>(george);
    LVL 3

    Assisted Solution

                List<int> george = new List<int>();
                List<int> bob;
                bob = new List<int>(george);
                bob = george.GetRange(0, george.Count);

    Open in new window


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now