使用Struct保留原始数据进行比较以确定IsDirty C# [英] Using Struct to hold original data for comparison to determine IsDirty C#

查看:147
本文介绍了使用Struct保留原始数据进行比较以确定IsDirty C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了辅助对象来保存原始属性值以检查更改,并在新值与原始值不匹配时标记用户.我曾经看到一个示例,其中有人实现了IEditable并对两个属性都使用了结构 支持和原始值的副本.

I have used secondary objects to hold original property values to check for changes and flag the user if the new value(s) do not match the original values.  I once saw an example where someone implemented IEditable and used a struct for both the property backing and a copy of the original values.

我对何时以及为什么使用结构体超出了我在MS文档中所读内容的理解有点模糊,并且在这种情况下似乎不应该使用该结构体.我想知道是否有人在这方面有经验或有比较聪明的方法来比较价值 并且当它们更改时,标志变脏,如果将标志更改回原始值,则标志变脏.出于性能/GC的原因,我只是在看Struct,但我可以很轻松地继续从事此工作.

I am a bit fuzzy on when and why to use a struct beyond what I read in MS documentation and it would seem that a struct should not be used in this case.  I was wondering if anyone has had any experience in this area or has a slick way to compare values and flag is dirty when they change and unflag isdirty if it is changed back to the original value.  I was just looking at a Struct for performance/GC reasons, but I can easily continue down the road I have been on with this.

谢谢

LD

推荐答案

结构与类相似,但权重较轻.在需要大量内存实例的情况下很有用,有时结构不需要初始化实例/对象:这意味着可以在结构内部直接访问值,其中 一个类,您需要该类的实例才能从内存中访问值.

structure is similar to class, but light weighted. It is useful where huge number of memory instances are required, sometime structure does not need instance/object to be initialised: which means values can be directly accessed inside a structure where in a class you need the instance of the class to access the values from memory.

http://www.codeproject.com/Articles/265755 /网络中类与结构之间的差异

致谢

joon


这篇关于使用Struct保留原始数据进行比较以确定IsDirty C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆