LINQ Study Note – 02

Three Actions In LINQ, we always work with objects, instead of the data source. Therefore, in the LINQ pattern, we always have three actions. Obtain the data source Create the query Execute the query Regarding the data source, the data source LINQ work with should support generic IEnumerable<T> interface; In other words, LINQ serves as…

LINQ Study Note – 01

LINQ works by using extension methods in C#, as LINQ won’t change the IEnumerator behind the scene. Func and Action Func type is common when we use LINQ to process, fetch and modify data or data collection in C#. Func itself can take 17 generic types as parameters. The last generic type parameter describes the…

Function Body Expression in C#

Function body expression is convenient when we make a less complicated function in C#. The body expression can decrease our workload dramatically when we are developing a large project. Original Function Function body Expression The function above is quite simple. It takes three parameters and returns the average value of the three parameters. The following…

Double and Float Tip in C#

I wrote a code snippet that day, and Visual Studio throws an error message regarding type conversation between Double and Float. This is the original code: As you can see, I declared a variable named number, and its data type is Float. The number’s value is 1.35. However, Visual Studio throws the error as: Literal…

Generic in C# – Basic Practice Example

Generic is a feature of C# programming language, which helps us save a lot of repeating works in our journey. It is efficient and widely used in practice. Background Imaging, we need to add many items into a list; and these items might be String, Integer, etc. Without Generic, we need to write at least…

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…