Seven Things about C#

A beginners tutorial, where each article highlights 7 important things about a specific feature of the C# programming language.

Follow publication

7 Things about C#: Types

Joe Mayo
Seven Things about C#
17 min readAug 8, 2023
Bright shapes of different types
C# has objects of different types and shapes

A type is a name given to some container that holds data of a specific size and shape. e.g. an int is a type that holds an integer number, a char is a type that holds a symbolic character, and a Recipe might be a complex type that holds ingredients and instructions.

With the C# type system, the big win for you is in productivity for your coding experience. C# is referred to as a strongly typed or type safe language. This means that you can only assign a value to a compatibly typed variable. It’s productive because the compiler catches type safety violations as soon as you build the app. That way, you can find and fix an entire category of errors in your app right away. The alternative would be to not find those errors and need to deal with them some time in the future where those errors might be even more problematic, difficult to detect, and expensive to correct.

Note: On type safety, the C# compiler will emit an error and not compile the app on type errors. e.g. trying to assign incompatible types, like a string to an int. These are called compile-time errors. Another type of error that can occur is a run-time error that the compiler wasn’t able to detect, which occurs when the application is running.

1 — There are several built-in types

C# has a few categories of built-in types including: integrals, floating point, other primitive types, and reference types. This section is a brief overview and we’ll dive deeper into some of the more complex subjects in other parts of this series.

You’ve seen examples of how to declare a variable with a type, in this format:

<type> <variable name> = <value>;

Here’s an example:

bool isCSharpCool = true;

Here, the <type> is bool, the <variable name> is isCSharpCool, and the <value> is true. Because C# is strongly typed, you can only pass a bool type value to a bool type variable. In the case of the above example, isCSharpCool can only be true or false. Setting it to a number, string, or other object would result in a compile-time error.

As you’re going through each of these sections, take note of the Range of each type (where applicable). They help you decide which type to use.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Seven Things about C#
Seven Things about C#

Published in Seven Things about C#

A beginners tutorial, where each article highlights 7 important things about a specific feature of the C# programming language.

Joe Mayo
Joe Mayo

Written by Joe Mayo

Author, Instructor, & Independent Consultant. Author of C# Cookbook: — http://bit.ly/CSharpCookbook — @OReillyMedia #ai #csharp #Web3

No responses yet

Write a response

Jual 1000 Like Facebook Murah Jasa Perbanyak Like Facebook Indonesia Share Facebook
Jual Like Facebook http://ttlink.com/url/14610192
Jasa Like Facebook https://vk.com/wall338329419_196
Like Facebook Murah
Jasa Share Facebook
Jasa Like Fanpage
Jasa Comment Facebook
Jasa View Facebook
Jual Followers Facebook...

--