C# Code Snippets Data Type Conversion

C# Data Type Conversion

In this code snippet, we will learn how to perform data type conversions in C#. C# has many different data types. You might find yourself needing to convert from one data type to another. This can be done implicitly by just assigning the value of one variable to another and the conversion will happen automatically. For example, assigning a short to int can be done implicitly as short is just a smaller int. Meanwhile converting a string to an int has to be done explicitly. 

C# Code Snippets Data Types

C# Data Types

In this code snippet, we will take a look at data types in C#. Data types are used to define the type of data a variable can hold. For example, to store whole numbers you can use int, string for text, char for a single character, double for numeric values with decimal points … Data types also differ in size, byte can hold values from 0 to 255, short can hold values from -32,768 to 32,767, int can hold values from -2,147,483,648 to 2,147,483,647, … 

C# Code Snippets Arrays

C# Arrays

In this code snippet, we will learn how to use arrays in C#. Arrays are like boxes, each box is accessible by a number called an index. They are zero-based. This means that the first box in the array has an index of 0, not 1.

C# Code Snippets Fields and Properties

C# Fields and Properties

In this code snippet, we will learn how to implement fields and properties in C#. Fields are just normal variables but declared directly inside of a class. Even though you can make fields public, you shouldn’t(use a property instead). Only use fields locally inside the class.

C# Code Snippets Params Keyword

C# Params Keyword

In this tutorial, we will learn how to use the params keyword in C#. The params keyword is used to define an array of input parameters for a method. Instead of explicitly defining every single one we can just pass in an array of parameters. As you can imagine when you have a lot of parameters this becomes very useful.

C# Code Snippets Access Modifiers

C# Access Modifiers

In this code snippet, we will learn how to use access modifiers in C#. Access modifiers are used to define the access level of types and members. The following access modifiers are available: public, private, protected, internal, protected internal, private protected. 

C# Code Snippets Methods

C# Methods

In this code snippet, we will learn about methods in C#. A method is basically a code block with a name. It can have input parameters to pass data into the code block and it can have a return type to return data out of the code block. A method can be called by writing its name followed by a set of parentheses.

C# Code Snippets Generics

C# Generics

In this code snippet, we will learn about generics in C#. You can make generic classes, properties, methods, and parameters. If we make something generic this means it doesn’t have a type. Or better said the type is determined at compile time.

C# Code Snippets Class

C# Class

In this code snippet, we’ll take a look at classes in C#. A class is like a blueprint to make an instance of an object. Inside a class, you can define class members like methods, properties, etc. Depending on the access modifier(public, private, …) set for each member we can control to who that specific member will be accessible.

Advertisment ad adsense adlogger