C#

IEnumerable and IEnumerator in C# with real time example

We will discuss here what is IEnumerable, IEnumerator, what are differences between them, where should we use IEnumerable and where to IEnumerator, once we will finish our discussion it will be clear, which one would be best for which situation and why, so let’s see it with example To better understand we will create a list of age List<int> ages = new List<int>(); ages.Add(10); ... By Ali Adravi   On 29 Mar 2013  Viewed: 33,051
  • oops
  • c#

Convert object to json and json to object in C#

In this article we will see how to convert an object to json string or how to convert a json string to an object in C#, we will try to write a generic class with two methods, one for converting an object to json and other for converting json string to an object. I searched internet to get if there is anything like this with .net but could not found any which we can use directly, so let's... By Ali Adravi   On 16 Jun 2013  Viewed: 27,316
  • json
  • c#
  • asp.net

Overloading and Overriding in C# with example

In my early day career in many interviews I asked same question, what is overloading and overriding so decided to write this small article which may help someone. We will see here in detail about the overloading, overriding and then differences between them. --- **Overloading:** --- is the mechanism to have more than one method with same name but with different signature (parameters). A... By Hamden   On 31 Mar 2013  Viewed: 26,643
  • overloading
  • c#
  • oops

Interface in C# with real time example

In this article we will discuss about interface in C# with real time example, it properties, implementations and pros and cons as well. 1. An interface can never be instantiated e.g. ICar car = new ICar(); It’s wrong. 2. It only contains signature of its methods. 3. An interface has neither constructor nor fields. 4. It is also not permitted to have access modifier on its methods. 5. Its... By Ali Adravi   On 18 Aug 2013  Viewed: 21,463
  • interface
  • c#
  • oops

Image gallery in asp.net mvc with multiple file and size

Image gallery in asp.net mvc or in any other language can be achieved by using different free JavaScript libraries. What we need for a good image gallery, at least we need images in two sizes to show thumbnail and then the original image on clicking the image. In this article we will write a small method to calculate the new image size and save images in multiple sizes. To upload image we will... By Ali Adravi   On 10 Jan 2015  Viewed: 21,056
  • mvc
  • c#
  • image
  • image-gallery
  • asp.net

Send email in background thread in C# aps.net

How to send email in a new thread in asp.net by using Gmail account or any other account or you can say a page where we can test out all the settings like SMTP Server, Email From, Email To, Email Password, Port Number, Email DeliveryMethod or Secure Socket etc. In this article we will see how to send email in background thread with CCed and BCCed functionality. Here is the page... By Hamden   On 13 Sep 2013  Viewed: 13,450
  • email
  • asp.net
  • c#

Linq inner join, left outer join on two lists in C# with example

Joining two generic lists in linq is tricky, in this article we will see how we can join two lists by using inner join and then by using outer join. Using inner join is quite similar to sql inner join but outer join is a little different, so we will see it with example code as well as records (output). So let's check the data, two generic lists which we will use in our example List1:... By Hamden   On 25 Sep 2013  Viewed: 12,118
  • linq
  • c#

Abstract Class in C# with Example

The purpose of an abstract class is to provide a common definition of base class that multiple derived classes can share, and can be used only as a base class and never want to create the object of this class. Any class can be converted into abstract class by adding abstract modifier to it. Common features of an abstract class: 1. An abstract class cannot be instantiated. 2. An abstract class... By Ali Adravi   On 21 Aug 2013  Viewed: 10,913
  • c#
  • asp.net
  • oops

How to fill datatable from datareader in C# without dataadapter?

Most of the developer use DataAdapter to fill the DataSet and then take the first table from the data set, which is quite slow, why can't we use DataReader to read the data and use datatable's Load method to load the reader into it, in this article we will see how we can load a table faster and easier way, even without using the DataSet and DataAdapter. First of all set our connection string... By Alicia Gonzalez   On 09 Jun 2013  Viewed: 8,316
  • datatable
  • data-reader
  • c#

How to create windows service in C# visual studio 2010

Creating windows service in C# is really easy but when we need to create first time we face many problems so in this post we will try to learn everything about window service. In this article we will create a windows service which will run after a particular interval, and time should be configurable and code to write log in a text file as well as send email if there is any error to execute the... By Ali Adravi   On 30 Apr 2013  Viewed: 6,997
  • c#
  • windows service

Static Class in C# why and when with examples

Static class, static method and static constructor are some common questions which are asked in most interviews. A static class is basically the same as a non-static class, but there in one difference, a static class cannot be instantiated, means we cannot use new keyword to create an object of the class. Even we cannot create any parameterized constructor because to pass the constructor value we... By Ali Adravi   On 01 Jan 2015  Viewed: 6,279
  • oops
  • c#

Nested Gridview binding in asp.net with collapsible feature

ASP.Net GridView binding is really easy but nested binding is a little bit tricky. We need to create two row for every single row one for normal row data and other for nested grid. There are two way to create multiple rows, one is by using the JavaScript by manipulating the html and other is directly from code behind, which we will use in our example, really it is not easy but very easy. We will... By Ali Adravi   On 03 Dec 2014  Viewed: 5,391
  • asp.net
  • gridview
  • c#

Covariance and Contravariance in C# 4.0 with example

C# the language, right from the very beginning is always supported covariance and contravariance but in most simple scenario, now in C# 4.0 we have full support of covariance and contravariance in all circumstances, generic interface and generic delegates, other C# types already support from first version of C#. These two terms sounds like technically scary as we will see they are incredibly... By Ali Adravi   On 29 Mar 2013  Viewed: 3,844
  • c#
  • oops

Constant ReadOnly and Static in C# with real life examples

Whether I should use Constant or ReadOnly or Static Variable, how to decide it, what are the reasons to choose Constant, ReadOnly or Static. It depends on the situation, usability and location to access. We are going to discuss each of these one by one and compare and check why we can use Constant and not the ReadOnly or Static variable. Why to use ReadOnly and not the Constant or Static variable... By Ali Adravi   On 03 Apr 2015  Viewed: 3,178
  • constact
  • readonly
  • static
  • c#
  • oops

Add facebook twitter and google plus in C# MVC application

You need to share your website content with faceboo, twitter and google+ to increase traffic of your website. it's quite easy to implement. You need just a helper class and one line code in your page to call that helper class and done. so let's first write the helper class public static class SocialNetworkingHelper { #region[Twitter helper Method] private... By Ali Adravi   On 13 Jan 2013  Viewed: 2,979
  • mvc
  • c#

Linq dynamic order by a list with example

Sort a list dynamically is easy, in this article we will create a class to sort the source dynamically by passing source, column and sort order. Let’s write our class and then we will see it with example, create a new class DynamicSort public static class DynamicSort { public static IQueryable<T> OrderBy<T>(this IQueryable<T> source , string columnName, bool... By Hamden   On 07 Sep 2013  Viewed: 2,277
  • linq
  • c#

enum in C# and conversion

An enumeration type (also known an enumeration or an enum) provides an efficient way to define a set of named integral constants that may be assigned to a variable to make programming clear, understandable and manageable. There are ways of using, like how to use enum in switch and case statement, how to convert a text to enum or number to enum to compare, we will discuss here all these points in... By Hamden   On 27 Mar 2013  Viewed: 2,220
  • c#
  • oops

Polymorphism in C# with example

Polymorphism is derived from two Latin words, 1. Poly means many 2. Marphose means forms. By using inheritance, a class can be used as many types, say we have a Person which may be a Professor, may be a Student, may be Clerk. So in this article we will see some example of Polymorphism. When we derive a class from base class it inherits all the method, properties, fields and events of the base... By Hamden   On 01 Jun 2013  Viewed: 2,120
  • c#
  • polymorphism
  • oops

Array in C# - single, multiple and jagged array

An array can be initialized in several ways, it can store a single value or series of values, every element must be set of same type, C# supports single-dimensional arrays, multidimensional arrays (also call rectangular array) and array-of-arrays (referred jagged arrays), let’s discuss features of array in C# like how to declare array in C#, How to initialize values to an array, how to define the... By Ali Adravi   On 24 Mar 2013  Viewed: 2,062
  • c#
  • array
  • asp.net

How to use linq query on a datatable in C#

Is it possible to perform a linq query on datatable, answer is no because datatable’s row collection, DataRowCollection does not implement IEnumerable<T> so we cannot perform linq query on it. But if there is any way to convert our datatable data row collection into IEnumerable, then surely we can. In this article we will see how to convert a datatable inot IEnumerable and perform Linq query and... By Charles Fuller   On 25 Jun 2013  Viewed: 1,851
  • datatable
  • linq
  • c#
12