TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Amresh S
NA
437
17.3k
How to Clone a Class instance without reference?
Oct 27 2016 8:16 AM
Hi All,
I'm trying to clone a class instance, which have rich collection of internal property values. Theses data are fetched from the database. I want to clone this instance in which the changes made in that instance will not affect the real one time created instance. Please refer the below code snippet:
public
class
DB_Data
{
public
DB_Data Data
{
get
;
internal
set
; }
public
DB_Data()
{ }
public
void
DB_Schema()
{
// code to get data from DataBase;
}
}
Now, I want a copy/clone of the instance which contains the DataBase data. My problem is, when I assign a new set of values to the instance, the referred instance value gets affected. Since the info fetched form the data base is a complex process, I don't want the copy variable to be initialized with real-data base info by repeated function call to the method DB_Schema(). is there any way to do this?
Kindly share your ideas. Thanks in advance.
Regards,
Amresh S.
Reply
Answers (
2
)
How to delete rows in a datagridview and database
How to connect to a remote MySQL server using C#?