I need to save a C # dict where I can store elements based on IntPtr and enumeration (when using canable to int, if that helps). In other words, if I get the same match between IntPtr and enum (named sp_playlist_type), I need to get the same result, but only then (this is also important). I decided that I would create a structure containing two and override GetHashCode (), but then I need a hashing algorithm that does not duplicate two numbers, and generates the same result every time the same number is present.
I think that based on the way you create Tuple GetHashCode and Equality, you can:
Dictionary<Tuple<IntPtr, YourEnum>, YourResultType>
, .NET 4.0, .
,
. GetHashCode(), . -, .
GetHashCode()
. XOR - - .
- , . :
private string GetKey(IntPrt prt, sp_playlist_type playlist_type) { return string.format("{0}#{1}", prt, type) }
, - :
mydic.add(GetKey(ptr, playlist_type), myvalue);
GetHashCode, , , , .
Equals , MSDN.
In this case, it is recommended to override GetHashCode . Probably, in this case XOR IntPtr and enumeration (LS 32-bit IntPtr in a 64-bit system).
Source: https://habr.com/ru/post/1791017/More articles:Forward stdout to a file in a Qt application - c ++Проблема с сохранением JQuery с вращением изображения - jqueryПроверьте, имеет ли SWF фокус - javascriptprevent opening page on iframe? - phpAWS SES for Email: Email Verification Required? - amazon-web-servicesHow can I format (fairly print) a multidimensional array for debugging? - pretty-printWhat is the advantage of RTSP over plain HTTP for static files? - language-agnosticAdding a delay in the application (for debugging) - c #Datastore for user data - design Q - database-designFacebook kiosk like feature - facebookAll Articles