Access Const Property in C#

In our development, we have to treat a Constant Property as a static member, if we need to reference this value. In other words, we have to access the member by using the type name, instead of the object name. Example The code snippet above is a Book class in a C# project. It has…

Case Study – Event Practice in C#

In C# practice, we always use Event as an observer for property modification. In this post, I am sharing a practice case regarding piggy bank monitoring. Background A piggy bank can help us with saving an amount of money that we planned. Every time, we deposit gold coins into the piggy bank, the balance will…

C# OOP Case Study: Initialization with a base parameter

I was studying my C# programming course material that day and came across an initialisation with a reference parameter. Case Background We are making a grade book for a student in his/her class. In the code, we are stimulating a scenario that we input the grade mark into his/her record. Every time, we input a…

C# Case Study – Delegate as a Method in Practice

Case Background A courier company ships parcels in the local area. There are four zones in the company’s business area. The shipping fees are a certain percentage of the given item price. Some destinations are a bit dangerous or far from the company’s depot, which has an additional risk fee $25. Zone 1 – 25%…

Event in C#

Event in C# is based on the mechanism that delegate used to work.  Event is useful for broadcasting information (or message) to and receiving data (or message) from other parts of the program.   Event allows the program to communicate asynchronously and help us build a more responsive application.  Besides, Event can be switched on and off as…

Delegate in C#

Delegate is a way that we can declare a variable that holds a reference to a function in our program.  It gives us an opportunity to change the function that will be called at a run time.  Besides, Delegate gives us a way to logically separate different parts of our application from each other, without having to…

Keyword readonly and static in C#

Access restriction of a variable in a class is a broad topic in C#; we define the restriction by adding the keyword in front of our variables. In some cases, we may have some member or variables in our class, and we don’t want other objects or classes amend their value. In this case, keyword…

Add a test file to C# project via Command Line Terminal

Unit Test is important in C# development journey. In this post, I am going to talk about how to add a test file via command line terminal in Windows 10 and we compile the project in Visual Studio Code. Start A New Project I start a new project in a directory named TestProject. Type in…

Reflection on Flow Control in C#

In C#, Flow-Control is used regularly.  It determines our program’s logic.   I have encountered some issues while using them, even though the syntax is quite simple.  These issues are not complex, but it can be serious if I ignore them. While in C# The While statement is straight forward, it keeps running till the variable i reaches…

Namespace in C#

Introduction Namespace in C# development is very heavily used regularly; it is helpful when we develop a relatively large or complex project.  For instance, .NET uses namespace to organise its classes. When it comes to using namespace in C#, it allows us to access the class of namespace by using namespace.classname syntax.  Alternatively, we can use keyword…