c# - 将一个对象转换到另一个对象

标签 c# casting class-design

我必须上课。让我们说发票和临时发票。 两者具有相同的属性(全部相同)。假设我使用发票类创建了一个对象。我可以将该对象转换为我使用 tempInvoice 创建的另一个对象吗??

例如:

Invoice invoiceobj= getInvoice(int? id) //a method return a invoice object

TempInvoice tempInvoiceObject = invoiceobj// (Need to do it and fill tempInvoice by Invoice Values.even as a new memory location o set by reference.)

最佳答案

除非 Invoice 派生自 TempInvoice

关于c# - 将一个对象转换到另一个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3641951/

相关文章:

c# - 动态使用运行时编译的程序集

c# - Android c# 按钮重叠

Java:当 B 实现 A 时从 List<B> 转换为 List<A>?

c# - 使用公共(public)成员有什么好处/坏处/不必要的吗?

c# - 将下拉列表值保存到 JavaScript 变量中

c# - Quickfix/n,如何禁用商店和日志工厂?

c++ - "invalid cast from type ' const myClass ' to type ' int '",我怎样才能让它有效?

entity-framework - 使用 LINQ 和 TPT EF 时如何转换为子类?

design-patterns - 我如何知道何时创建界面?

java - builder 模式会不会做得太多?