Custom dictionary class in c# - c#

I am trying to create a custom dictionary with some methods. I created a struct containing the information for lanes in my game. One information tells me if there is an enemy in the lane(Occupied) and the other if we completed that lane so no more enemies will come there(Completed).
I am able to get the initial information out, but cannot update them with my methods. I construct it by adding all 7 lanes, where none of them are either occupied or completed. Then throughout my game, I would like to mark them either as completed or occupied or free, but even after a lot of time searching around, I couldn't figure out the proper way to call for an update of these items inside my laneInfo property.
public struct laneInfo
{
public bool Occupied;
public bool Completed;
}
public class laneInfoClass : Dictionary<int, laneInfo>
{
public laneInfo laneinfo;
public laneInfoClass()
{
for(int i = 0; i <= 6; i++)
{
this.Add(i, false, false);
}
}
public void Add(int key, bool occupied, bool completed)
{
laneinfo.Occupied = occupied;
laneinfo.Completed = completed;
this.Add(key, laneinfo);
}
public void Complete()
{
laneinfo.Completed = true;
}
public void Occupy()
{
laneinfo.Occupied = true;
}
public void Free()
{
laneinfo.Occupied = false;
}
}
Thanks!

Its fairly rare that your class would inherit from a dictionary/list/collection (why?), more often than not what you are actually modelling is a class which has an instance member which is that same dictionary/list/collection.
In addition, you need some way to notify your class which particular lane you're trying to update, you use an integer key so work with that:
public struct LaneInfo
{
public bool Occupied {get;set;}
public bool Completed {get;set;}
}
public class LaneInfoContainer
{
private Dictionary<int, LaneInfo> laneInfoDict = new Dictionary<int, LaneInfo>();
public LaneInfoContainer()
{
for(int i = 0; i <= 6; i++)
{
this.Add(i, false, false);
}
}
public void Add(int key, bool occupied, bool completed)
{
var laneInfo = new LaneInfo();
laneinfo.Occupied = occupied;
laneinfo.Completed = completed;
this.laneInfoDict.Add(key, laneinfo);
}
public void Complete(int key)
{
laneInfoDict[key].Completed = true;
}
public void Occupy(int key)
{
laneInfoDict[key].Occupied = true;
}
public void Free(int key)
{
laneInfoDict[key].Occupied = false;
}
}
I suspect you might also need some way to read the info about your lanes too, add methods such as
public bool IsComplete(int key)
{
return laneInfoDict[key].Complete;
}

The answer to your question is that you should not use a Dictionary. Iterating a List<T>.Contains is faster than Dictionary<TKey, TValye> lookup for 7 items, especially if you are accessing them by index integer 0-6.
Part from that, Dictionary<TKey, TValue> is already generic and so there is no need to inherit from it. Sometimes you would wrap it, for various reasons (one might be locking). But if it is just for a few methods you can simply add extension methods to the Dictionary<int, LaneInfo>.
public static class LaneExtensionMethods
{
public static bool IsComplete(this Dictionary<int, LaneInfo> dictionary, int key)
{
return dictionary[key].Complete;
}
}
// Use
var d = new Dictionary<int, LaneInfo>();
var isComplete = d.IsComplete(1);
I often replace the int with a type to avoid bugs and confusion in code. This would in your case also allow for specialized extension methods. Casting has zero CPU cost (its just cosmetics in code).
public enum LaneId : Int32 { }
public static class LaneExtensionMethods
{
public static bool IsComplete(this Dictionary<LaneId, LaneInfo> dictionary, LaneId key)
{
return dictionary[key].Complete;
}
}
// Use
var d = new Dictionary<LaneId, LaneInfo>();
var laneId = (LaneId)1; // We cast from integer to LaneId, but use LaneId type everywhere in our app
var isComplete = d.IsComplete(laneId);

Related

C# constructors sharing code and then referencing properties already set [duplicate]

I have two constructors which feed values to readonly fields.
public class Sample
{
public Sample(string theIntAsString)
{
int i = int.Parse(theIntAsString);
_intField = i;
}
public Sample(int theInt) => _intField = theInt;
public int IntProperty => _intField;
private readonly int _intField;
}
One constructor receives the values directly, and the other does some calculation and obtains the values, then sets the fields.
Now here's the catch:
I don't want to duplicate the
setting code. In this case, just one
field is set but of course there may
well be more than one.
To make the fields readonly, I need
to set them from the constructor, so
I can't "extract" the shared code to
a utility function.
I don't know how to call one
constructor from another.
Any ideas?
Like this:
public Sample(string str) : this(int.Parse(str)) { }
If what you want can't be achieved satisfactorily without having the initialization in its own method (e.g. because you want to do too much before the initialization code, or wrap it in a try-finally, or whatever) you can have any or all constructors pass the readonly variables by reference to an initialization routine, which will then be able to manipulate them at will.
public class Sample
{
private readonly int _intField;
public int IntProperty => _intField;
private void setupStuff(ref int intField, int newValue) => intField = newValue;
public Sample(string theIntAsString)
{
int i = int.Parse(theIntAsString);
setupStuff(ref _intField,i);
}
public Sample(int theInt) => setupStuff(ref _intField, theInt);
}
Before the body of the constructor, use either:
: base (parameters)
: this (parameters)
Example:
public class People: User
{
public People (int EmpID) : base (EmpID)
{
// Add more statements here.
}
}
I am improving upon supercat's answer. I guess the following can also be done:
class Sample
{
private readonly int _intField;
public int IntProperty
{
get { return _intField; }
}
void setupStuff(ref int intField, int newValue)
{
//Do some stuff here based upon the necessary initialized variables.
intField = newValue;
}
public Sample(string theIntAsString, bool? doStuff = true)
{
//Initialization of some necessary variables.
//==========================================
int i = int.Parse(theIntAsString);
// ................
// .......................
//==========================================
if (!doStuff.HasValue || doStuff.Value == true)
setupStuff(ref _intField,i);
}
public Sample(int theInt): this(theInt, false) //"false" param to avoid setupStuff() being called two times
{
setupStuff(ref _intField, theInt);
}
}
Here is an example that calls another constructor, then checks on the property it has set.
public SomeClass(int i)
{
I = i;
}
public SomeClass(SomeOtherClass soc)
: this(soc.J)
{
if (I==0)
{
I = DoSomethingHere();
}
}
Yeah, you can call other method before of the call base or this!
public class MyException : Exception
{
public MyException(int number) : base(ConvertToString(number))
{
}
private static string ConvertToString(int number)
{
return number.toString()
}
}
Constructor chaining i.e you can use "Base" for Is a relationship and "This" you can use for same class, when you want call multiple Constructor in single call.
class BaseClass
{
public BaseClass():this(10)
{
}
public BaseClass(int val)
{
}
}
class Program
{
static void Main(string[] args)
{
new BaseClass();
ReadLine();
}
}
When you inherit a class from a base class, you can invoke the base class constructor by instantiating the derived class
class sample
{
public int x;
public sample(int value)
{
x = value;
}
}
class der : sample
{
public int a;
public int b;
public der(int value1,int value2) : base(50)
{
a = value1;
b = value2;
}
}
class run
{
public static void Main(string[] args)
{
der obj = new der(10,20);
System.Console.WriteLine(obj.x);
System.Console.WriteLine(obj.a);
System.Console.WriteLine(obj.b);
}
}
Output of the sample program is
50 10 20
You can also use this keyword to invoke a constructor from another constructor
class sample
{
public int x;
public sample(int value)
{
x = value;
}
public sample(sample obj) : this(obj.x)
{
}
}
class run
{
public static void Main(string[] args)
{
sample s = new sample(20);
sample ss = new sample(s);
System.Console.WriteLine(ss.x);
}
}
The output of this sample program is
20
Error handling and making your code reusable is key. I added string to int validation and it is possible to add other types if needed. Solving this problem with a more reusable solution could be this:
public class Sample
{
public Sample(object inputToInt)
{
_intField = objectToInt(inputToInt);
}
public int IntProperty => _intField;
private readonly int _intField;
}
public static int objectToInt(object inputToInt)
{
switch (inputToInt)
{
case int inputInt:
return inputInt;
break;
case string inputString:
if (!int.TryParse(inputString, out int parsedInt))
{
throw new InvalidParameterException($"The input {inputString} could not be parsed to int");
}
return parsedInt;
default:
throw new InvalidParameterException($"Constructor do not support {inputToInt.GetType().Name}");
break;
}
}
Please, please, and pretty please do not try this at home, or work, or anywhere really.
This is a way solve to a very very specific problem, and I hope you will not have that.
I'm posting this since it is technically an answer, and another perspective to look at it.
I repeat, do not use it under any condition. Code is to run with LINQPad.
void Main()
{
(new A(1)).Dump();
(new B(2, -1)).Dump();
var b2 = new B(2, -1);
b2.Increment();
b2.Dump();
}
class A
{
public readonly int I = 0;
public A(int i)
{
I = i;
}
}
class B: A
{
public int J;
public B(int i, int j): base(i)
{
J = j;
}
public B(int i, bool wtf): base(i)
{
}
public void Increment()
{
int i = I + 1;
var t = typeof(B).BaseType;
var ctor = t.GetConstructors().First();
ctor.Invoke(this, new object[] { i });
}
}
Since constructor is a method, you can call it with reflection. Now you either think with portals, or visualize a picture of a can of worms. sorry about this.
In my case, I had a main constructor that used an OracleDataReader as an argument, but I wanted to use different query to create the instance:
I had this code:
public Subscriber(OracleDataReader contractReader)
{
this.contract = Convert.ToString(contractReader["contract"]);
this.customerGroup = Convert.ToString(contractReader["customerGroup"]);
this.subGroup = Convert.ToString(contractReader["customerSubGroup"]);
this.pricingPlan= Convert.ToString(contractReader["pricingPlan"]);
this.items = new Dictionary<string, Member>();
this.status = 0;
}
So I created the following constructor:
public Subscriber(string contract, string customerGroup) : this(getSubReader(contract, customerGroup))
{ }
and this method:
private static OracleDataReader getSubReader(string contract, string customerGroup)
{
cmdSubscriber.Parameters[":contract"].Value = contract + "%";
cmdSubscriber.Parameters[":customerGroup"].Value = customerGroup+ "%";
return cmdSubscriber.ExecuteReader();
}
notes: a statically defined cmdSubscriber is defined elsewhere in the code; My main constructor has been simplified for this illustration.
In case you need to run something before calling another constructor not after.
public class Sample
{
static int preprocess(string theIntAsString)
{
return preprocess(int.Parse(theIntAsString));
}
static int preprocess(int theIntNeedRounding)
{
return theIntNeedRounding/100;
}
public Sample(string theIntAsString)
{
_intField = preprocess(theIntAsString)
}
public Sample(int theIntNeedRounding)
{
_intField = preprocess(theIntNeedRounding)
}
public int IntProperty => _intField;
private readonly int _intField;
}
And ValueTuple can be very helpful if you need to set more than one field.
NOTE: most of the solutions above does not work for structs.
Unfortunately initializing struct fields in a method called by a constructor is not recognized by the compiler and will lead to 2 errors:
in the constructor: Field xxxx must be fully assigned...
in the method, if you have readonly fields: a read-only field cannot be assigned except in a constructor.
These can be really frustrating for example when you just need to do simple check to decide on which constructor to orient your call to.

cache the variable in constructor C#

i have one class with constractor like this
public class product_new : NK.Objects._product_new
{
private int Count_Per_Page;
public product_new(int count_per_page)
{
this.Count_Per_Page = count_per_page;
}
public int CountOP///////count of pages
{
get
{
return number_of_pages(Count_Per_Page);
}
}
as you see the CountOP is return a int value and it is connect to sql database to return this value.
private int number_of_pages(int tedad_per_pages)
{
return Q.Get_Back_Number_Of_Pages(
tedad_per_pages,
tbl_name,
"",
new Queries.Cmd_Parameters());
}
in several time if create object from this class the CountOP is not changed but the function number_of_pages is released and connect to the sql database.
how can i cache this variable?
Try using static Dictionary<int, int> - one dictionary for all the instances:
public class product_new : NK.Objects._product_new {
// Simplest, but not thread safe; use ConcurrentDictionary for thread safe version
private static Dictionary<int, int> s_KnownAnswers = new Dictionary<int, int>();
// Lazy: do not execute expensive operation eagerly: in the constructor;
// but lazyly: in the property where we have to perform it
public int CountOP {
get {
int result = 0;
// do we know the answer? If yes, then just return it
if (s_KnownAnswers.TryGetValue(Count_Per_Page, out result))
return result;
// if no, ask RDMBS
result = number_of_pages(Count_Per_Page);
// and store the result as known answer
s_KnownAnswers.Add(Count_Per_Page, result);
return result;
}
}
...
}
Introduce a private backing-field that holds the value and initialize its value within your constructor. Now you can return the variables value within your getter instead of hitting the database every time you call the getter.
public class product_new : NK.Objects._product_new
{
private int Count_Per_Page;
private readonly int _CountOP;
public product_new(int count_per_page)
{
this.Count_Per_Page = count_per_page;
this._CountOP = number_of_pages(count_per_page);
}
public int CountOP///////count of pages
{
get
{
return this._CountOP;
}
}
Apart from this I strongly suggest to have a look at Mircrsofts naming-conventions.
Change to use a backed property:
private int _npages = -1;
public int CountOP///////count of pages
{
get
{
if(_npages == -1)
_npages = number_of_pages(Count_Per_Page);
return _npages;
}
}

Serializing C# Objects having delegate fields using JSON.NET?

Although my problem is more of C# / JSON.NET related I will give you the context.
I am building a game in which I need to implement a Challenge System. For those who might be unfamiliar, Challenges are basically clusters of achievements/tasks that you accomplish to earn rewards.
So I need to have Challenges that have list of tasks that are tracked in game.
e.g. Challenge XYZ has 3 task
1. Kill 3 Enemies
2. Collect 2 Stars
3. Reach Score of 100
So first of all I have a GameState Class. I am using GameState object to store all the in game data.
public class GameState
{
public static string SaveKey = "GameState";
public int Blips { get; set; }
public int ChainClearedCount { get; set;}
public int DotClearedCount { get; set; }
public int RetryUsedCount { get; set; }
public int ContinueUsedCount { get; set; }
public int LevelAttemptedCount { get; set; }
public int LevelClearedCount { get; set; }
public int LevelPlayedCount { get; set; }
public int LevelFailCount { get; set; }
public Dictionary<ChainCombos, int> ComboCountBook = new Dictionary<ChainCombos, int>();
public Dictionary<ChainType, int> ChainTypeCountBook = new Dictionary<ChainType, int>();
public Dictionary<LevelType, int> LevelTypeCountBook = new Dictionary<LevelType, int>();
public Dictionary<GameModes, int> LevelModeCountBook = new Dictionary<GameModes, int>();
public Dictionary<GameModes, int> HighScoreBook = new Dictionary<GameModes, int>();
public Dictionary<GameModes, int> HighLevelBook = new Dictionary<GameModes, int>();
public Dictionary<LevelType, int> PlaygroundLevelCountBook = new Dictionary<LevelType, int>();
public Dictionary<GameDifficulty, int> PlaygroundDifficultyCountBook = new Dictionary<GameDifficulty, int>();
//Followed By Constructors , Accessor Methods and Event Subscribers for GameCore Module
}
So the Game State object's respective fields are updated by the GameCore class (not shown) whenever any event occurs.
I am using JSON.NET to serialize this GameState object so that it can be used to load the game data on game launch.
Now I have my Task Class:
The key part of Task Class is Func Value;
This stores a delegate that is used to query the GameState object.
public class Task
{
protected bool Incremental = true;
Func<int> Value;
public event Action<float> OnProgress;
protected int targetValue;
protected int currentValue;
public bool Completed = false;
public float Progress;
[JsonConstructor]
public Task(int targetValue, Func<int> Value, bool Incremental, bool ConnectedByDefault) //Constructor
{
this.targetValue = targetValue;
this.Value = Value;
this.Incremental = Incremental;
if (ConnectedByDefault)
{
ConnectToGame();
}
}
public void ConnectToGame()
{
GameController.GameStateEvent += UpdateProgress;
CalculateProgress();
}
public void DisconnectFromGame()
{
GameController.GameStateEvent -= UpdateProgress;
}
protected virtual void OnComplete() { Completed = true; }
protected void UpdateProgress(GameState s)
{
if (Value() > currentValue)
{
CalculateProgress();
if (OnProgress != null)
{
OnProgress(Progress);
}
}
}
protected void CalculateProgress()
{
currentValue = Value();
if (currentValue < targetValue)
{
if (Incremental)
{
Progress = ((float)currentValue / (float)targetValue);
}
else
{
Progress = 0f;
}
}
else
{
Progress = 100f;
OnComplete();
}
}
}
Now if i have to declare a Task i do something like this
Task a = new Task(200, () => GameController.CurrentGameState.DotClearedCount, true, false);
As you can see what I am doing is sending a delegate that will be allocated to Value field of the task and will be used internally to query the Game-state object's indicated field (in this case DotClearedCount).
My issue is that I have to serialize the task objects since I need to keep track of player's task progress over multiple game sessions.
JSON.NET is incapable of serializing delegate fields of objects as far as I know. I mean I checked storing a delegate and the JSON output was something like "delegatEntry = null".
So I am unable to wrap my head around the issue of how I am going to save my Task objects such that when they are deserialized and constructed by JSON.NET they get linked back to my GameState object.
I looked in LINQ queries I am still unable to find anything concrete that will help me. I mean as far as I understood I can build LINQ queries on objects like Lists and Dictionaries but then again my GameState objects have a lot of Dictionaries that I want to target separately for different tasks.

What pattern am I missing

I have the following interface
interface IConsoleHistory
{
void Add(string entry);
HistoryEntry GetNextEntry();
HistoryEntry GetPreviousEntry();
void ResetHistoryMarker();
void Delete(HistoryEntry entry);
void DeleteEntireHistory();
}
public class HistoryEntry
{
public HistoryEntry(string value, int index, bool isCommand)
{
Value = value;
Index = index;
IsCommand = isCommand;
}
public string Value { get; private set; }
public int Index { get; private set; }
public bool IsCommand { get; private set; }
}
Based on that, I implemented an InMemoryHistory:
public class InMemoryHistory : IConsoleHistory
{
protected List<string> History { get; private set; }
private int _currentIndex;
public InMemoryHistory() :this(new List<string>())
{
}
protected InMemoryHistory(List<string> history)
{
History = history;
_currentIndex = -1;
}
public virtual void Add(string entry)
{
History.Insert(0, entry);
}
public HistoryEntry GetNextEntry()
{
if (GetHighestIndex() > _currentIndex)
{
_currentIndex++;
return ReturnAtIndex(_currentIndex);
}
return null;
}
private int GetHighestIndex()
{
return History.Count - 1;
}
private int GetLowestIndex()
{
return History.Count > 0 ? 0 : -1;
}
public HistoryEntry GetPreviousEntry()
{
if (_currentIndex > GetLowestIndex())
{
_currentIndex--;
return ReturnAtIndex(_currentIndex);
}
_currentIndex = -1;
return null;
}
private HistoryEntry ReturnAtIndex(int index)
{
return new HistoryEntry(History[index], index, false);
}
public void ResetHistoryMarker()
{
_currentIndex = -1;
}
public void Delete(HistoryEntry entry)
{
if (History.ElementAtOrDefault(entry.Index) != null)
{
History.RemoveAt(entry.Index);
}
}
public void DeleteEntireHistory()
{
History.Clear();
}
}
Now I wanted to have a file based history. To keep the code DRY I wanted to inherit from the InMemoryHistory and just persist the whole List after every addition.
public class FileBasedHistory : InMemoryHistory
{
private readonly string _fileName;
public FileBasedHistory():this("history.txt")
{
}
public FileBasedHistory(string fileName) :base(GetHistoryFromFile(fileName))
{
_fileName = fileName;
}
public override void Add(string entry)
{
base.Add(entry);
WriteToDisk();
}
private void WriteToDisk()
{
using(var textWriter = new StreamWriter(_fileName, false, Encoding.UTF8))
{
History.ForEach(textWriter.WriteLine);
}
}
private static List<string> GetHistoryFromFile(string fileName)
{
if (!File.Exists(fileName))
return new List<string>();
return File
.ReadAllLines(fileName)
.ToList();
}
}
That works like a charme. What bothers me though is that I need the static GetHistoryFromFile method. It's not really a big deal but I wonder if I'm missing a pattern that would be more appropriate for this situation?
UPDATE
As Keith already suggested. It's also the inheritance approach that kinda bothers me. Inheritance should always be a question of is a.
You can not say: "A FileBasedHistory is a InMemoryHistory"
So I wonder if I should try to use the StrategyPattern for this. Or maybe write an AbstractConsole that implements parts of the logic but leaves room for extensions. Any suggestion on how to refactor it?
I find it odd you are passing in a list as a constructor. You don't have to do it that way at all...
rather than thinking of your GetHistoryFromFile as creating a new list, think of it as a method to load into an existing list ( it becomes more generally useful that way also... as it could load multiple files into a history ).
Also removing and clearing don't work properly for writing to disk...
Also writing a line by line to disk is likely to get quite slow...
Also, your InMemory and File based storage may be suffering from Coincidental coupling. Meaning while they are similarish at the moment, there's a likely chance for them to diverge. eg, if your disk based system used rolling history files and cached history. So don't get too attached to the InMemory and File to remain in a inheritance structure, it may be easier to break them apart
I think you've got it just perfect. GetHistoryFromFile only applies to a FileBasedHistory, so it makes sense that it should be there.
You can use Iterator here. These three methods used only for iterating over your data:
HistoryEntry GetNextEntry();
HistoryEntry GetPreviousEntry();
void ResetHistoryMarker();
And these methods are for managing data:
void Add(string entry);
void Delete(HistoryEntry entry);
void DeleteEntireHistory();
I think this is a different responsibilities, and I'd moved them to different classes.

Request for Comments: fast hashed base class for dictonary keys

In one of my aplications I have to use many dictonarys with custom objects as keys. To improve the performance of the lookups I implemetet an base class that overrites GetHashCode.
It seams to work but somehow I still have a bad fealing about it so I decided to post my code and I would be gratefull for any tips or coments.
(omg I forgot the code :D )
abstract class FastHashed
{
private static Dictionary<Type,ulong> _instanceCounters = new Dictionary<Type,ulong>();
private int hash;
protected FastHashed()
{
Type instanceType = this.GetType();
if(! _instanceCounters.ContainsKey(instanceType)) _instanceCounters.Add(instanceType,0);
this.hash = ((instanceType.ToString())+(_instanceCounters[instanceType]++.ToString())).GetHashCode();
}
public override int GetHashCode()
{
return hash;
}
}
Edit: Do not mess with the hashing if you do not have to. This "sollution" is slower and less reliable then the default GetHashCode().
Edit:
I did some performance testing with the Equatec profiler and a simple console aplication.
class Program
{
static readonly int cycles = 50000;
static Dictionary objectsDict = new Dictionary();
static Dictionary foosDict = new Dictionary();
static void Main(string[] args)
{
foo[] foos = new foo[cycles];
object[] objects = new object[cycles];
for (int i = 0; i < cycles; i++)
{
foos[i] = new foo();
objects[i] = new object();
foosDict.Add(foos[i], i);
objectsDict.Add(objects[i], i);
}
ObjectHash(objects);
FooHash(foos);
}
static void ObjectHash(Object[] objects)
{
int value;
for (int i = 0; i < cycles; i++)
{
value = objectsDict[objects[i]];
}
}
static void FooHash(foo[] foos)
{
int value;
for (int i = 0; i < cycles; i++)
{
value = foosDict[foos[i]];
}
}
class foo
{
private readonly int _hash;
public foo()
{
_hash = this.GetHashCode();
}
public override int GetHashCode()
{
return _hash;
}
}
}
The results:
- FooHash 26 774 ms
- ObjectHash 7 ms
Obviously the defualt GetHashCode is the best choice.
This is not thread-safe.
If you only care about reference equality, why do you have different counters for different types?
If all you want is to prevent Hashes from being computed multiple times, why not something like this (or a variant with generics if the dictionary will only hold objects of a certain type):
public class ObjectWithCachedHashCode : IEquatable<ObjectWithCachedHashCode>
{
private int _cachedHashCode;
public object Object { get; private set; }
public ObjectWithCachedHashCode(object obj)
{
Object = obj;
_cachedHashCode = obj.GetHashCode();
}
public override int GetHashCode()
{
return _cachedHashCode;
}
public bool Equals(ObjectWithCachedHashCode other)
{
return other!=null && Object.Equals(other.Object);
}
public override bool Equals(object other)
{
return Equals(other as ObjectWithCachedHashCode);
}
}
Edit: Made class compatible with Dictionary
You can mark the hash variable readonly.
But to be honest, in C# where you have single inheritance it is not always wise to "waste" the inheritance to implement such specific behavior. Suppose you suddenly wants to inherit from a base class that "does" something. Save class inheritance to modelling purposes, not implementing details.
As far as I can see, this is just functionally equivalent to the object.GetHashCode() default implemntation, apart from being slower and non thread-safe. What is it that makes "Fast Hash" fast?

Categories