Skip to main content
gamedev.net
🔒 Locked

.net casting

Started by Barn Door 0 replies 250+ views
Original Post
Barn Door
Barn Door
Hi, When and when not does casting in .net have a runtime overhead? What does casting involve? I was under the impression that in C++, for example, casting might just stop the compiler throwing an error at compilation time but that it might also invlove a constructor call at runtime in order to create the object that''s being casted to. Cheers, BD.
Zipster
Zipster
Casting primitive types in C++ was really just a way of telling the compiler how you wanted certain data treated. They were primitive types, so the compiler just added a few extra instructions to take care of the cast. It wouldn''t create anything new, it would just treat it differently.

In .NET it could be different. For example, in C# there really aren''t any "primitive-types"... a better term for them would be built-in types, but even when you have something like this - int myInteger; - int is really just an alias for the Int32 object. Thus, when you cast between different built-in types in C# there could be some kind of implicit conversion function being called.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.