[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


How do I Create New instance of an Object?

Posted on 2009-04-27
Medium Priority
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

CuteBug earned 100 total points
ID: 24240989
List<int> bob = new List<int>(george);

Assisted Solution

BalkisBr earned 100 total points
ID: 24241013
            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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

873 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