C# Code Snippets as operator

C# as Operator

In this tutorial, we will learn how to use the as operator in C#. The as operator is used to cast objects into different types. It is similar to the is operator. They can both be used to check if an object is of a certain type. If the conversion is successful the converted object gets returned else a null will be returned.

C# Code Snippets is operator

C# is Operator

In this tutorial, we will learn how to use the is operator in C#. The is operator is very similar to the as operator. They can both be used to check if an object is of a certain type. Additionally as can be used to perform type casting. If the object matches the specified data type true gets returned else false will be returned.

C# Code Snippets Conversion Operator Overloading

C# Conversion Operator Overloading

In this code snippet, we will take a look at conversion operator overloading in C#. Conversion operators can be overloaded just like regular operators. This is useful when you want to be able to convert your custom object to another type. We have two types of conversions, implicit and explicit. Implicit conversion can be “just done” no special syntax is required. Meanwhile, explicit conversion requires casting.

C# Code Snippets Reflection

C# Reflection

In this code snippet, we will take a look at reflection in C#. Reflection is used to get metadata(information) about an object at runtime. We can get members(properties, methods) of objects and their data types. Reflection is also used for late binding. The ability to see the metadata of an object is for example, useful is when you use generics, as you don’t necessarily know the data type of a generic member until the object is created.

C# Code Snippets Operator Overloading

C# Operator Overloading

In this code snippet, we will take a look at operator overloading in C#. Just like methods operators can be overloaded too. In the code below we have an example with geometric shapes. If we use the + operator on two objects of GeomentricShapes we get an error. This happens because the compiler doesn’t know what is supposed to happen when the  + operator is used on a GeomentricShapes object. We have to overload the + operator and write the code to be executed when two GeomentricShapes objects are added together. 

C# Code Snippets Attributes

C# Attributes

In this code snippet, we will take a look at attributes in C#. Attributes are used to add additional information(metadata) to code. For example, you can use [Serializable] to indicate that a class can be serialized. Or as I will demonstrate in the code example a method can be marked as obsolete and Visual Studio will warn you when you attempt to use the obsolete method. 

MAX II CPLD USB Blaster Connection

MAX II CPLD Basic Getting Started Tutorial

This tutorial will cover the hardware and software setup for the MAX II CPLD. We will also make a simple design to upload to the CPLD. This little dev board can be picked up on eBay or Aliexpress for around 10 bucks(including the USB blaster). It’s cheap, easy and simple compared to some of the other FPGA dev boards. Despite that, I didn’t find a lot of tutorials and projects(compared to the Arduino stuff) with this board so I thought I’d make a tutorial.

C# Code Snippets Preprocessor Directives

C# Preprocessor Directives

In this code snippet, we will take a look at data types in C#. Preprocessor directives are statements that get executed before compilation. They are designated by the # sign. Preprocessor directives can, for example, be useful when debugging code. Suppose we can make an if statement that checks whether the program is in debug mode. If so we would enable some diagnostic output otherwise we wouldn’t.

C# Code Snippets GUID

C# GUID

In this code snippet, we will take a look at GUIDs in C#. A GUID or a Globally Unique Identifier(also known as a Universally unique identifier )  is an alphanumeric sequence of character that make up a completely unique identifier(at least in theory). One place a GUID can be used is with databases to serve as a unique ID.