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… Continue reading var keyword constraints as class fields in C#
Category: .NET/C#
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”,… Continue reading Enforcing date pattern with DateTime.TryParseExact method
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… Continue reading Constraint with properties in passing as reference