С# Как я могу скопировать все значения из первого класса во второй ⇐ C#
-
Гость
С# Как я могу скопировать все значения из первого класса во второй
I have following code on c# Have two instance of different classes. First class it's ancestor of second. And I just want copy all values from ancestor to second class. How I can do it? I mean How to do it better? If I don't want to create constructor and others function in class.
For example of classes:
ItemsInformationWithWarehouses TowarIMagazyn = new ItemsInformationWithWarehouses(); TowarIMagazyn.magid1 = i.magid1; TowarIMagazyn.magid2 = i.magid2; TowarIMagazyn.dokmsid1 = i.dokmsid1; TowarIMagazyn.dokmsid2 = i.dokmsid2; TowarIMagazyn.Dostawa = i.Dostawa; TowarIMagazyn.Symbol = i.Symbol; TowarIMagazyn.Towar = i.Towar; TowarIMagazyn.Partia = i.Partia; TowarIMagazyn.PartiaE = i.PartiaE; TowarIMagazyn.SSCC = i.SSCC; TowarIMagazyn.PartiaO = i.PartiaO; TowarIMagazyn.Pozostalo = i.Pozostalo; TowarIMagazyn.JM = i.JM; TowarIMagazyn.sWc1 = i.sWc1; TowarIMagazyn.sWc2 = i.sWc2; TowarIMagazyn.sWc3 = i.sWc3; TowarIMagazyn.sWc4 = i.sWc4; TowarIMagazyn.sWc5 = i.sWc5; TowarIMagazyn.DataWstawienia = i.DataWstawienia; TowarIMagazyn.WyprodukowanoDla = i.WyprodukowanoDla; TowarIMagazyn.IndeksOdbiorcy = i.IndeksOdbiorcy; TowarIMagazyn.IndeksDostawcy = i.IndeksDostawcy; public class ItemsInformation { public int magid1 { get; set; } public int magid2 { get; set; } public int dokmsid1 { get; set; } public int dokmsid2 { get; set; } public string Dostawa { get; set; } public string Symbol { get; set; } public string Towar { get; set; } public string Partia { get; set; } public string PartiaE { get; set; } public string SSCC { get; set; } public string PartiaO { get; set; } public string Pozostalo { get; set; } public string JM { get; set; } public string sWc1 { get; set; } public string sWc2 { get; set; } public string sWc3 { get; set; } public string sWc4 { get; set; } public string sWc5 { get; set; } public string DataWstawienia { get; set; } public string WyprodukowanoDla { get; set; } public string IndeksOdbiorcy { get; set; } public string IndeksDostawcy { get; set; } } public class ItemsInformationWithWarehouses : ItemsInformation { List Magazyny = new List(); } public class Magazyny { public string SymbolMagazyn { get; set; } public string fromMagazyn { get; set; } public int fromMagazynMagId1 { get; set; } public int fromMagazynMagId2 { get; set; } public int MagazynMagId1 { get; set; } public int MagazymMagId2 { get; set; } } I want do like this CopyValueOfElementsFromFirstToSecond(TowarIMagazyn,i)
Источник: https://stackoverflow.com/questions/743 ... -to-second
I have following code on c# Have two instance of different classes. First class it's ancestor of second. And I just want copy all values from ancestor to second class. How I can do it? I mean How to do it better? If I don't want to create constructor and others function in class.
For example of classes:
ItemsInformationWithWarehouses TowarIMagazyn = new ItemsInformationWithWarehouses(); TowarIMagazyn.magid1 = i.magid1; TowarIMagazyn.magid2 = i.magid2; TowarIMagazyn.dokmsid1 = i.dokmsid1; TowarIMagazyn.dokmsid2 = i.dokmsid2; TowarIMagazyn.Dostawa = i.Dostawa; TowarIMagazyn.Symbol = i.Symbol; TowarIMagazyn.Towar = i.Towar; TowarIMagazyn.Partia = i.Partia; TowarIMagazyn.PartiaE = i.PartiaE; TowarIMagazyn.SSCC = i.SSCC; TowarIMagazyn.PartiaO = i.PartiaO; TowarIMagazyn.Pozostalo = i.Pozostalo; TowarIMagazyn.JM = i.JM; TowarIMagazyn.sWc1 = i.sWc1; TowarIMagazyn.sWc2 = i.sWc2; TowarIMagazyn.sWc3 = i.sWc3; TowarIMagazyn.sWc4 = i.sWc4; TowarIMagazyn.sWc5 = i.sWc5; TowarIMagazyn.DataWstawienia = i.DataWstawienia; TowarIMagazyn.WyprodukowanoDla = i.WyprodukowanoDla; TowarIMagazyn.IndeksOdbiorcy = i.IndeksOdbiorcy; TowarIMagazyn.IndeksDostawcy = i.IndeksDostawcy; public class ItemsInformation { public int magid1 { get; set; } public int magid2 { get; set; } public int dokmsid1 { get; set; } public int dokmsid2 { get; set; } public string Dostawa { get; set; } public string Symbol { get; set; } public string Towar { get; set; } public string Partia { get; set; } public string PartiaE { get; set; } public string SSCC { get; set; } public string PartiaO { get; set; } public string Pozostalo { get; set; } public string JM { get; set; } public string sWc1 { get; set; } public string sWc2 { get; set; } public string sWc3 { get; set; } public string sWc4 { get; set; } public string sWc5 { get; set; } public string DataWstawienia { get; set; } public string WyprodukowanoDla { get; set; } public string IndeksOdbiorcy { get; set; } public string IndeksDostawcy { get; set; } } public class ItemsInformationWithWarehouses : ItemsInformation { List Magazyny = new List(); } public class Magazyny { public string SymbolMagazyn { get; set; } public string fromMagazyn { get; set; } public int fromMagazynMagId1 { get; set; } public int fromMagazynMagId2 { get; set; } public int MagazynMagId1 { get; set; } public int MagazymMagId2 { get; set; } } I want do like this CopyValueOfElementsFromFirstToSecond(TowarIMagazyn,i)
Источник: https://stackoverflow.com/questions/743 ... -to-second
Мобильная версия