-
Efficiently handling DBNull in C#
Hello friends, Let’s go through about DBNull today. DBNull represents a nonexistent value returned from the database. In a database, for example, a column in a row of a table might not contain any data whatsoever. That is, the column is considered to not exist at all instead of merely not having a value. A DBNull object…
-
Working with Factory Method Pattern
Hello friends, Today we will go through another creational design pattern called Factory Method. Before talking about its implementation let’s begin with defining it. Factory method pattern is similar to simple Factory pattern with a few difference. Unlike Simple factory, here client doesn’t call the factory class instead it calls the factory interface. Factory interface…
-
Working with Simple Factory Pattern
Hello friends, Today we will go through another creational design pattern called Simple Factory. Before talking about its implementation let’s begin with some fundamental questions as in the following. Purpose of the Factory pattern I can think of two main objectives of using the Factory pattern. One is to achieve loose coupling between the client…
-
Constraint with properties in passing as reference
Hello friends, I happened to encounter this trouble while trying to pass the reference of a Property. public class LinkedListQ : QNode { private QNode head = null; public QNode Head { get { return head; } } class Program { static void Main(string[] args) { LinkedListQ que = new LinkedListQ(); que.ReverseList(ref que.Head); //Error “A property, indexer or dynamic member access may not be passed as an out or ref…
-
Remove Duplicates in Dataset Efficiently
Hello guys, Do you remember the pain of removing duplicates in fetched dataset by looping, comparing etc. it can be handled easily by using DataView.ToTable Method. The syntax is below. DataView.ToTable(bool distinct, string[] columnNames) distinct: If it’s true, the returned DataTable contains rows that have distinct values for all its columns specified in the second…
-
Data Grid Best Practices in WPF
Hello friends, While working on WPF, I came to know some good Data grid tips and wanted to share you the same. Issue WPF Data Grid is not reflecting the changed Item Source. Solution If using MVVM pattern, Refresh the item source by below command. CollectionViewSource.GetDefaultView(<Your Data Grid collection name>).Refresh(); Issue How to open a…
-
Implement Square Root Method
Hello friends, I am here again with another example where we will see how to find square root of a number without using .NET library method. Let’s start with basic one though it’s not efficient as it considers all the number starting from 0.001 till the difference of multiplying both numbers and the number given…
-
Row Versioning Based Isolation Levels in SQL Server
Hello guys, Row Versioning based Isolation levels are very useful in reducing blocking. Which are. Read Committed (default) Isolation level with READ_COMMITTED_SNAPSHOT database option is ON. Snapshot Isolation level with the ALLOW_SNAPSHOT_ISOLATION database option is ON. Read committed isolation using row versioning provides statement-level read consistency however Snapshot isolation provides transaction-level read consistency. Statement-level read…
-
Direct Casting, IS and AS Operator in C#
Hello friends, Below are the available ways in C# when you cast one data type to another. Direct casting Direct cast is most common way of casting one type to another, however it yields exception if casting can’t be done. Below is the example to demonstrate the same. object length = 3.2; int test = (int)length; //Fails in…
-
Changing default route in ASP.NET MVC
Hello friends, As we know that ASP.NET MVC by default takes following setting available in RouteConfig file (under App_Start folder). routes.MapRoute( name: “Default”, url: “{controller}/{action}/{id}”, defaults: new { controller = “Home”, action = “Index”, id = UrlParameter.Optional } ); This means when you run the application, Home controller will be invoked and it’s Index method will be executed by taking parameter id (if any). you can change…
