Category: .NET/C#

  • Ranges and indices in C# 8.0

    Hello friends, Today we will go through another C# 8 feature called Ranges and indices Range and Indices are the great additions in the C# world. Due to these constructs, handling indexes have become fairly easy. Below is a summary of the changes in this feature. System.Index represents an index in an array or sequence.…

  • Default Interface Implementation in C# 8.0

    Hello friends, Hope you are doing well. I am starting a series to go through the new C# 8 features one by one to cover all the new features and enhancements. C# 8 is getting released soon along with .NET Core 3.0 and it has several new features and enhancements to give more power to…

  • Enable CORS in ASP.NET Core Web API

    Hello friends, As we know that in Web API, CORS is by default disabled due to security reasons. and hence if a client tries to access API in different server and port, you can end up with error as “Origin http://localhost:xxxx is not allowed by Access-Control-Allow-Origin“ To enable it in ASP.NET Core Web API, there…

  • String and StringBuilder in Design and Action

    Hello Friends, Lets have a look at old yet relevant point about String and String Builder. Both constructs are meant to manipulate the strings but in their own way. A string (namespace: System.String ) is a sequential collection of Unicode characters that represent text. A String object is immutable (read-only) and a sequential collection of…

  • var keyword constraints as class fields in C#

    Hello friends. Hope you are doing well!! Wish you happy new year!! I am here to talk about the var keyword constraint, when using it in the class level fields in C#. Sometimes , we get a question that why can’t we use var keyword in initializing the class level fields. Let’s have a look at…

  • Enforcing date pattern with DateTime.TryParseExact method

    Hello friends, Today we will go though a useful method of datetime class called TryParseExact.  You can use this method to specify the pattern in which you want user to enter the dates. There are two overloads as following. TryParseExact(String, String, IFormatProvider, DateTimeStyles, DateTime)TryParseExact(String, String[], IFormatProvider, DateTimeStyles, DateTime) Example: var isValid = DateTime.TryParseExact(Convert.ToString(value), “d MMM yyyy”,…

  • 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…

  • 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…