C# reflection, interfaces, abstract class, generics, ref vs out, C# versions 4,5,6 and features.

C# Reflection - What is Assembly?

Assembly is the main unit in .NET applications. Assembly is a collection of types and its information. There are two types of assemblies: Executable files (EXE) Libraries (DLL) Both type of assemblies includes information about types and its members in its metadata. There are three ways to get Assembly instances: Geting assembly instance from type...

Continue Reading

C# Reflection - Type class

A Type class is an important class in C# reflection. Type class represents class types, interface types, array types, value types, enum types, type parameters, generic type definitions, and open/closed generic types. Type class helps you to find properties, methods, events, fields, and constructors declared in a type. It also provides us the Assembly in which the type is dec...

Continue Reading

C# Reflection - MemberInfo Class

MemberInfo class provides a quick look of all the members in a Type. Below is the same code to get all members of a Type. static void Main(string[] args) { Type type = typeof(Program); foreach(MemberInfo member in type.GetMembers()) { Console.WriteLine(member.Name + ":" + member.MemberType); } } MemberInfo MemberType property MemberInfo prov...

Continue Reading

C# Reflection - Getting Constructors

C# reflection Type class provides two methods for getting the constructors in any Type. GetConstructors() //Returns all the constructors GetConstructor() //Returns only the specific constructor with match your given criteria. By default, all the above methods returns public constructors of a Type. To get the private, protected, and static constructors you have to u...

Continue Reading

.NET Threading Interview Questions Series - Part 1

Q 1.  What is the difference between Process and Thread? A process is started when you start an Application. A process is a collection of resources like virtual address space, code, security contexts etc. A process can start multiple threads. Every process is start with a single thread called primary thread. You can create n number of threads in a process. Threads share...

Continue Reading

.NET Threading Interview Questions Series - Part 2

Q 21. What is the class hierarchy of wait handles? Q 22. What is ManualResetEvent and how it is different between AutoResetEvent? ManualResetEvent is also a synchronization mechanism similar to AutoResetEvent which works on bool variable. If the bool variable is false, it blocks the thread. If true, it unblocks the threads. ManualResetEvent provides the sa...

Continue Reading

C# Convert string to int

In C#, there are there ways for converting string to int. Each way has its own advantages and disadvantages. These ways are: int.Parse method int.TryParse method (Best way) Convert.ToInt32() method int.Parse method int.Parse method converts string input into integer. It takes the string input and returns int as output. static void Main(...

Continue Reading

ConcurrentDictionary in C# - Introduction, Examples

ConcurrentDictionary is one of five collection classes introduced in .NET 4.0. It exists in System.Collections.Concurrent namespace. ConcurrentDictionary is thread-safe collection class to store key/value pairs. ConcurrentDictionary can be used with multiple threads concurrently.  Without ConcurrentDictionary class, if we have to use Dictionary class with mult...

Continue Reading

ConcurrentQueue in C# - Introduction and Examples

C# ConcurrentQueue is a thread-safe collection class. It is introduced in .NET 4.0 with other concurrent collection classes. It provides a thread-safe First-In-First-Out (FIFO) data structure. You can read more about Queue here. ConcurrentQueue exists in System.Collections.Concurrent namespace ConcurrentQueue is a wrapper around generic Queue class. Queue...

Continue Reading

ConcurrentStack in C# - Introduction and Examples

ConcurrentStack is a thread-safe generic collection class introduced in .NET 4.0 framework. It provides a Last-In-First-Out (LIFO) data structure. You can read more about Stack here. ConcurrentStack is like wrapper around Stack class. Stack class is not thread-safe. ConcurrentStack provides thread-safety. It internally uses locking to synchronize different threads. Cr...

Continue Reading

Join our newsletter and get an occasional email with a technology and DotNetPattern.com news update.