简体   繁体   English

使用 C# 检查自定义 class 中的数据是否已更改

[英]Check if data in a custom class has changed using C#

I was curious what is the best way (preferrably faster one, from CPU standpoint) to see if data in my customer C# class has changed?我很好奇查看我的客户 C# class 中的数据是否发生变化的最佳方法是什么(最好是更快的方法,从 CPU 的角度来看)?

The class consists of various basic types: int , long , string , etc. and List< string > and List < uint > types. class 由各种基本类型组成: intlongstring等和List< string >List < uint >类型。

My idea was to convert this class data into byte[] array and do SHA1 on the result, but converting every member into a byte array seems to be quite a long undertaking so I'm wondering if there's a faster way.我的想法是将这个 class 数据转换为 byte[] 数组并对结果执行 SHA1,但是将每个成员转换为字节数组似乎是一项相当长的工作,所以我想知道是否有更快的方法。 I also thought to serialize it, but wouldn't it be an overkill for my purpose.我也想连载它,但这对我的目的来说不是太过分了。 (The resulting serialized byte array on my empty class is about 6000+ bytes!) (在我的空 class 上生成的序列化字节数组大约有 6000+ 字节!)

Anyway, what's your take on it?不管怎样,你怎么看?

You could implement the INotifyPropertyChanged Interface in your Class.您可以在 Class 中实现INotifyPropertyChanged接口。

That way all registered methods will be triggered if something changes.这样,如果发生变化,所有已注册的方法都会被触发。

See How to implement it查看如何实施

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM