C# Nullable Types, What Is Nullable Types In C#, The syntax of Nullable Type In C#, Declaring Nullable Types In C#, Nullable Types In C# Example

C# Nullable Types | What Is Nullable Types In C# with Example

In this article, we are going to learn about C# Nullable Types / Nullable Type In C#. Before defining Nullable types, Let’s understand why c# nullable types introduced? what is nullable type in c# and then how to use them?

Why C# Nullable Types?

To understand the answer, why c# nullable types? and follow the problem that nullable type can solve. The c# programming language support two kinds of data types.

  • Value type (e.g., struct, int, double, etc.)
  • Reference type (e.g., string, object, etc.)

Assigning a null value to a value is not possible until nullable types were introduced in .NET framework. By taking the advantage of nullable types now value type can store a null value.

A nullable type can hold a correct range of values of a value type (int, boolean etc.) plus NULL. This feature is really helpful when you are working with the database in real-time applications. In a real-time application, there are possibilities that database fields like boolean may need to hold true, false or undefined. Using this nullable type we can solve the problem of undefined.

The syntax of Nullable Type In C#

Declaring Nullable Types In C#

Nullable Types In C# Example

The following example will demonstrate the nullable types usage. number1 assigned to a null value and number2 with 22. Once the code is executed it will give you blank value because of nullable and second with 22 because the value is assigned.

The output of the program when compiled and executed


C# 8.0 Features, New Features In C# 8.0

C# 8.0 Features | New Features In C# 8.0

C# programming language is the most popular because every release makes the job easier. From past two decades, it has released seven versions now came up with c# 8.0. Let’s see C# 8.0 features.

New Features In C# 8.0 | C# 8.0 Features

  1. Default Implementation for Interfaces.
  2. Light Weight Classes.
  3. Nullable Types.

Default Implementation for Interfaces in C# 8.0

Default implementation for an interface is an exciting feature in C# 8.0. Until 7.0, we could only see interfaces only with abstract methods but now in .NET framework 8.0 added a default implementation for interface methods.

Using default implementation for interface has made drastic changes in development life cycle.

The default implementation of interfaces will provide a most powerful way to extend the classes that implement interfaces.

C# Light Weight Classes, records in C#

C# Light Weight Classes – Records in C#

C# Light weight classes allow creating a class more flexible. It’s beautiful and new way to build your class called as records. Records in c# enable creating POCO type objects very quickly. Records / C# Light Weight Classes also solve the problem of equality comparison of objects.

Creating a C# Light Weight Classes

The below example will help you to understand in implement immutable classes and auto implementation of properties. Person class has a private set property which can be initialized only by a constructor. This example you can see, how to initialize the dynamic object creation using LINQ.


C# Interfaces, Interfaces In C#, Interfaces In C# Programming, Features about Interfaces in c#, interfaces with realtime example, all about interfaces in C#

Interfaces In C# Programming – A Complete Guide

Interfaces in C# programming is a very crucial concept and quite confusing for a lot of developers to understand and implement. So I have created C# interfaces article to make sure, even a basic developer also can understand.

After going through this article, you will get the complete knowledge of interfaces like

  • What is an interface?
  • When to use interfaces?
  • Where to use interface?

C# Interfaces | Interfaces In C#

Let’s understand what c# interfaces are?.

Interfaces are declared using interface keyword. An interface is like a contract that all derived classes/interfaces should follow.

In other words, it’s like rules defined in the interface and these interface rules has to be followed by derived class or interfaces. So remember we are defining rules in interfaces and forcing them to follow in next subclasses.

Example: How to declare and implement interfaces in c#?

If you look at the above code, we have declared “IInput” interface with two methods (rules).

  • getkeyBoard()
  • getMouse()

In subsequent classes of Computer and Laptop, I am implementing the same rules defined in IInput Interface. I hope now you understood how to create rules and implement methods (rules) using interfaces in c#.

Features about Interfaces in c#

  • Interfaces are declared using interface keyword.
  • All methods in interfaces are by default public and we can’t change them.
  • An Interface contains methods with no implementations.
  • Interfaces may contain properties, methods, events, and indexers.
  • Any Interfaces cannot be Instantiated directly.