如何在 C# 中获取类中字段的默认值? [英] How can I get the default value of a field in a class in C#?
本文介绍了如何在 C# 中获取类中字段的默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有我的课程,我有非静态变量
Say I have my class, and I have the non-static variable
int x = 5;
代码运行后 x
改成别的东西,如何使用反射开始获取 x
的值?
After the code runs x
is changed to something else, how can I get the value x
started with using reflection?
推荐答案
简短的回答:你不能.
如果您实现某种自定义事务系统,那是可能的.开箱即用:没有运气.
If you implement some kind of custom transactional system, than it is possible. Out of the box: no luck.
是的,自定义事务系统可以非常简单:添加另一个用于记住"初始值的字段或属性.
And yes, the custom transactional system can be very simple: add another field or property that you use to 'remember' the initial value.
这篇关于如何在 C# 中获取类中字段的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文