Singleton Pattern – Design Pattern That Creates a Single Object

Singleton Pattern – Design Pattern That Creates a Single Object

Singleton pattern is a design pattern belonging to the creational group. Singleton ensures that only a single object of the class will be instantiated. Another important element of a Singleton is that an object is treated as a "global" variable, meaning that the object can be accessed from anywhere in the program. When a class is built on the Singleton pattern, it can only be instantiated once. Any other initialization requests will be directed to the only object being instantiated. In addition, the object of a Singleton class will not be instantiated until it is actually used. In this article,…
Read More
Proxy Design Pattern in C# – Controlling Object Access

Proxy Design Pattern in C# – Controlling Object Access

The proxy design pattern belongs to the structural group that controls the creation and access of objects. A proxy is usually a simple small object between the client code and the real (more complex) object that controls access to the real object. When the conditions are right, the proxy will delegate the client's request to the actual object for processing.What is a Proxy Design Pattern in C#?Imagine a one-stop shop in public offices (like in wards). Although there are many people in the ward in charge of different fields of work, the one-stop shop is the only place where people…
Read More
Decorator Pattern Layouts – Extending Objects Without Inheritance

Decorator Pattern Layouts – Extending Objects Without Inheritance

Decorator pattern is a design pattern belonging to the structural group. It provides the ability to extend an object by "attaching" a new variable or method to an object. Object is oblivious to the fact that it is being "decorated" with new methods and variables. This design pattern is suitable for systems that need to expand continuously. Decorator idea is relatively close to inheritance and you can easily understand this design pattern if you understand the idea of inheritance.In this lesson we will look at the idea, design, and implementation of this pattern in detail.What is the Decorator Pattern?The Decorator…
Read More
Const String Interpolation in C# 10 and .NET 6

Const String Interpolation in C# 10 and .NET 6

Text processing is the heart of every application building and it must be used. So today we will discuss Const String Interpolation in C# 10 and .NET 6. It makes the code more readable and more concise. So let's get started. If you want to improve StringBuilder performance in C# please follow our this post.Click Me. Const string implementation in C# 9: In C# 9.0 we have to use the "+" operator for the const string concatenation. let's see the example public const string A = "Hi "; public const string B = "How are "; public const string C…
Read More
Working with DateTime in C#

Working with DateTime in C#

In this article, we will discuss working with DateTime in C#. A DateTime object is commonly used for handling Date and time in .NET(Core). Let's dive into the DateTime object. You can improve your stringBuilder performance by following our below article.Improve StringBuilder performance in C# 1. How to create a DateTime in C#? We can create DateTime objects in multiple ways. A DateTime object can have multiple properties Iike Date, Time, Localization, culture, milliseconds, and kind. // Empty DateTime DateTime emptydateTime = new DateTime(); // Create a DateTime from date and time DateTime dateofbirth = new DateTime(1996, 22, 10, 8, 11,…
Read More
How to Boost Productivity as .NET Developer in Visual Studio

How to Boost Productivity as .NET Developer in Visual Studio

Welcome to mycodebit.com. Today we will discuss How to Boost Productivity as .NET Developer in Visual Studio 2022. Visula Studio is a Microsoft IDE that is used to develop many web, console and windows application. It is used in daily life of .NET developers so new .NET developer doesn't know the full features of Visual Studio that can increase the developer productivity dramatically. No one can denny that Visual studio is getting better in every release but without using its full power we can not increase the productivity as a .NET developers. I have listed some key features of Visual…
Read More
How to improve StringBuilder performance in C#

How to improve StringBuilder performance in C#

In this article, we will learn and discuss How to improve StringBuilder performance in C#. As we know string is an immutable type in C# and .NET. Whenever we modify a string a new string object is allocated into the memory with new string data. StringBuilder is used to address this issue with StringBuilder whenever a string is modified the memory allocation of the string is extended if the string size grows. Use of StringBuilderCache: StringBuilderCache is an internal class of .NET and .NET Core. When we have to create multiple instances of StringBuilder StringBuilderCache is used to optimize memory…
Read More
How to Generate Random Numbers in C#

How to Generate Random Numbers in C#

In this article, we are going to learn How to Generate Random Numbers in C#. C# provides us a class to generate random numbers that is named "Random". In random class, we can use the predefined method "Next()" to generate random numbers and numbers within a self-defined range. Let's move forward to code to see how does this class works. To use Random class and access its methods we have to initialize first the "Random" class with the new Keyword and after initializing e can access its members by its constructor. var random = new Random(); int num = random.Next();…
Read More
How to Implement Multiple Interfaces Having Same Method Name in C#

How to Implement Multiple Interfaces Having Same Method Name in C#

In this article, we are going to discuss How to Implement Multiple Interfaces Having Same Method Name in C#. What is interface in C#? In C#, Interfaces are like classes they can have methods properties, events, and indexers members. But interfaces only of signatures or declaration of methods. The implementation of these methods is done by classes that implement the interface implicitly or explicitly. C# allows us to implement multiple interfaces with the method names in one class which is derived by multiple interfaces. To understand this let's move to an example. Example: We have created two interfaces in this example…
Read More