> For the complete documentation index, see [llms.txt](https://dailyjournal.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dailyjournal.gitbook.io/notes/languages/c-sharp/types.md).

# Types

Value Types and Reference Types

## Value Types / Primitive Types&#x20;

* A variable of a *value type* directly contains their data.

> With value types, each variable has its own copy of the data, and it's not possible for operations on one variable to affect the other.

`bool`, `byte`, `sbyte`, `char`, `decimal`, `double`, `float`, `int`, `uint`, `nint`, `nuint`, `long`, `ulong`, `short`, `ushort`, `struct`, `enum`, `tuple`

<pre class="language-csharp"><code class="lang-csharp"><strong>(double Sum, int Count) t2 = (4.5, 3);    // tuple
</strong>Console.WriteLine($"Sum of {t2.Count} elements is {t2.Sum}.");
// Output:
// Sum of 3 elements is 4.5.
</code></pre>

## Reference Types / Non-Primitive Types

* A variable of a *reference type* contains a reference to their data (objects).

> With reference types, two variables can reference the same object; therefore, operations on one variable can affect the object referenced by the other variable.

`class`, `interface`, `delegate`, `record`, `object`, `string`, `dynamic`

```csharp
string a = "hello";
string b = "h";
// Append to contents of 'b'
b += "ello";
Console.WriteLine(a == b);
Console.WriteLine(object.ReferenceEquals(a, b));
```
