I am making a class that calls a callback function and I want it to pass some data in some cases but that data may vary. In C++ I would use void* but in C# it’s unsafe and it means it might get GCed. Is there any way of passing unknown type of data in C#?
Share
You’ve got two options:
Generics (which allow you to specify the type when you call the method… and the object will be properly typed within the method.)
Or System.Object (which means you’ll have to ascertain the object’s actual type inside your method and cast appropriately)