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

C# Func

In Microsoft Framework class library, there are some built-in delegates. Action, Predicate and Func are some of them. I have explained Action and Predicate in my previous posts. Action and Predicate delegates has restrictions. Action delegate can take only parameters and does not return anything. Predicate delegate can take parameters but returns only boolean value. To ret...

Continue Reading

C# Interface

C# Interface defines a group of related functionality. An interface defines only the definition of the functionality. All classes and structures which inherit from interface must implement the functionality defined in an interface. We can not create an instance of interface. In the interface declaration variable, we can only store the instance of the object that impleme...

Continue Reading

C# Predicate

Predicate is a pre-built delegate in the .NET framework class library. Delegates are used to store method which has same parameters and return types as specify in the delegate type. Predicate is a generic delegate. It takes one parameter and returns a boolean value. Predicate delegate is used for check whether a parameter meets specify condition or not. ...

Continue Reading

ref vs out parameters

This post is about difference between ref and out parameters. C# provides three keywords when you defining a method signature. These keywords are: params ref out By default, method arguments are passed by value. That means calling method pass a duplicate copy of data to the called method. If called method modifies the data, it will not visible to calling met...

Continue Reading

C# Generic Methods

In my previous post, I explained about Generics. C# also provides Generic Methods. We can create a method which defer the parameter data type until the method is called. These parameters are called Type parameters that means we can pass the actual data type later. Below is the example of Generic Method. static void Swap<T>(ref T input1, ref T input2) { T temp =...

Continue Reading

C# Generics

Generics are introduced in C# 2.0. It is the most powerful features of C#. In C# 1.0, when we design a class that use other types that is not known at defining the structure of the class, then type should be an object type. In the class, we have to typecast the type using boxing and unboxing and then we can use the type. Generics introduced the concept of type parameters. Wi...

Continue Reading

C# Hashtable

C# Hashtable class is a collection class where we can store data in the key/value pair. Hashtable is not type-safe. Hashtable is not generic and both key and value are based on object type. Hashtable is used to store unique keys data. If we try to assign value to already used key, it just overrides the previous stored data. It is based on the Hashing algorithm&n...

Continue Reading

C# using statement - Why and How?

This article is an introduction to the C# using statement and explain why and how to use it. I'll also describe features of using statement and examples of nested using. In C#, every object is using some resources managed or unmanaged internally. Client is responsible for life cycle of the object. Life cycle of the object means creation or destroying the object...

Continue Reading

C# Versions and Features

C# versions C# 1 comes in 2002 with .NET framework 1.0 and Visual Studio 2002 C# 2 comes in 2005 with .NET framework 2.0 and Visual Studio 2005 C# 3 comes in 2008 with .NET framework 2.0 and Visual Studio 2008 C# 4 comes in 2010 with .NET framework 4.0 and Visual Studio 2010 C# 5 comes in 2012 with .NET framework 4.5 and Visual Studio...

Continue Reading

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