Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

how to reinitilizing a value in list

The problem is due to referencing... In C# when you copy a list it copy reference of the previous object to your new list, therefore it is recommended to developer to Clone their objects.

For colon my list I used below code:

public static T CloneObject<T>(T
    using (var stream = new MemoryStream())
        var formatter = new BinaryFormatter();
        formatter.Serialize(stream, object);
        stream.Position = 0;
        return (T)formatter.Deserialize(stream);

So for clone your object just call this function.

you need to serialize all the dependable classes related to T class.

public class ClassT
    // your code

Categories : C#

Related to : how to reinitilizing a value in list
Recently Add
Get Existing Outlook Addin Information from External C# Application
What's the best way to share an instance of an object across many objects?
Searching a enum description containing a slash
C# how to properly make a http web GET request
Get ComboBox selected value form Form1 to another Form2
Pixel Format conversion
Why does my download queue break when called faster after each other?
How to define XML namespaces to be incuded in the header of XML request which will be send via invoke of a Web Service call?
eventlog source - string/message table lookup failed
What is the idea behind IIdentity and IPrincipal in .NET
How can the Wix Installer distinguish target builds?
Verifying if method was called with Moq
Send json data to SQL Server 2008
Cannot validate in MVC 5 authentication with both UserName and Email
Unioning two LINQ queries
How to block a number in Twilio
Pass object attribute to controller
C# nHibernate programatically set db password
How to add node at mouse click location on canvas?
Register boolean in Container
ASP MVC or/and Networking issues
Managing Single Quotes while calling on a Stored Procedure
Connection String to connect a SQL Server using another windows account
DynamicTableEntity PartitionKey and RowKey
The property content is set more than once.. WPF
How to change asp:ListView DataPager page from codebehind (c#)
Case-insensitive "contains" in Linq
Bootstrap Button_Click Event Not Firing
catch OnVisibilityChanged events
In C#, SQL connection is printing: 'System.Data.SqlClient.SqlDataReader'
© Copyright 2017 Publishing Limited. All rights reserved.