© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•12mo ago•
27 replies
Tempest

How to tell if a variable is a reference or value data type

Today I've been learning about the ref, in, and out keywords. I understand that some variables are value types and some are reference types but I haven't really found and easy way of being able to tell which is which.

I understand that if I use the class keyword it will be a reference type and if I use struct it will be value. Is it really as simple as that? Its just I've noticed how everything including primitives like int are inheriting the object class so does that mean outside of things that have been explicitly marked as struct are reference?

A related question is around 15 years ago I learned a little bit of c++ and I learned that if anything is bigger than the size of a pointer it should be passed by reference to avoid the overhead of copying it.
As primitives like int in c# are slightly larger than a primitive in c++ being an object instance should we be using ref, in and out wherever possible? I can see the value of using in wherever possible because so far in my learning it feels like that is the closest we have to passing const.

Thank you very much for your time and help.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ How to check if reference type field in mono_field_get_value is null
C#CC# / help
4y ago
❔ how to reference a variable in another script?
C#CC# / help
3y ago
❔ how to tell if a TCP request is a HTTP request
C#CC# / help
3y ago