I have one class
class MatchAddress
{
public string Name { get; set; }
public string Taluka { get; set; }
public string District { get; set; }
public string Pincode { get; set; }
public float Rank { get; set; }
}
I have create new list using this class as mentioned below
var dst = ds.Tables[0].AsEnumerable()
.Select(s => new MatchAddress
{
Name = s.Field<String>("officename").Trim().ToLower(),
Pincode = Convert.ToString(s.Field<double>("pincode")).Trim(),
Taluka = s.Field<String>("Taluk").Trim(),
District = s.Field<String>("Districtname").Trim(),
Rank = 0f
})
.ToList();
I have also initialize new list List<MatchAddress> lm;
Now I'm assign dst
list to lm
like below
lm = dst ;
foreach (MatchAddress ma in lm)
{
if (ma.Name == "xyz")
{
ma.Pincode = null;
}
}
after this sure the Property Pincode
for the list lm
set to null
where name = "XYZ".
and for that reason list lm
are update and set pincode field null .
but my question are that why that list lm also update the result of list dst.
and lm
list also set pincode null in the list dst
.
and we make the clone of the dst
list into lm
so why list lm
change the also list dst ??
I know to reason behind this not the answer why this happen if you know then please let me now.
I don't want to the answer of this question