C#

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: 47,530
  • interface
  • c#
  • oops

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: 44,578
  • 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: 41,181
  • json
  • c#
  • asp.net

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: 38,922
  • linq
  • c#

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: 38,105
  • email
  • asp.net
  • c#

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: 35,479
  • mvc
  • c#
  • image
  • image-gallery
  • 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: 34,582
  • overloading
  • c#
  • oops

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: 23,720
  • oops
  • 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: 18,742
  • 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: 13,795
  • datatable
  • data-reader
  • 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: 11,215
  • asp.net
  • gridview
  • 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: 8,610
  • c#
  • windows service

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: 7,585
  • constact
  • readonly
  • static
  • c#
  • oops

Singleton design pattern in c# with real examples

Singleton is a design pattern in which we allow a class to be instantiated only once and use again and again from entire application. In this article we will try to see different ways to create and Singleton class and pros & cons of all the ways, we will also write some code to test it, so we can understand what's going on **1. Singleton - Not Thread Safe **: Let's write the very basic... By Ali Adravi   On 03 Jul 2018  Viewed: 7,049
  • singleton
  • c#
  • design-pattern

Get list of country without database by using RegionInfo Class

RegionInfo class can be used to get the detail of any country and it's other country related information like country name, country code, currency, native name and many more. If we want to bind a drop down with the countries of world without creating database, then it will be the good option. There are many other information which can be used but for this article just we are going to see how we... By Alicia Gonzalez   On 16 Nov 2015  Viewed: 6,500
  • CultureInfo
  • RegionInfo
  • 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: 5,570
  • linq
  • c#

Read write xml in asp.net c#

Reading and writing in xml can be done in different ways, some common classes people use are XmlTextReader, XmlTextWriter , XmlDocument but we will use XDocument. By using the other classes say XmlTextReader we need to use the while loop to read and check every node by using XmlNodeType, for a long XML file which is not suitable. We need a way to search the exact node by providing Id of the... By Ali Adravi   On 20 Dec 2014  Viewed: 5,014
  • xml
  • xdocument
  • asp.net
  • 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: 4,977
  • 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: 4,548
  • c#
  • polymorphism
  • oops

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: 4,525
  • c#
  • oops
12