C#

What is Func, how and when it can be used, examples

Func is a predefined delegate. .Net have 17 Func delegates with different parameters from 1 to 17. Every Func delete last parameter is return type says TResult. It encapsulte a method which have zero (0) to 16 parameters, except the last one, rest of the parameters are function input parameter. Let's see how it is defined internally public delegate TResult Func<out... By Ali Adravi   On 05 Jun 2016  Viewed: 821
  • func
  • c#

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: 1,490
  • CultureInfo
  • RegionInfo
  • c#

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

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

Convert image to base 64 string and base 64 string to image in c#

Converting and image to base 64 from an image or from a path or converting a base 64 string to an image is quite easy. We will use MemoryStream to convert them. We will use two simple method one to convert the image to base 64 string and other to convert the base 64 string to image. Image can be saved wherever you want or show them anywhere on the page Code to convert the image into base 64... By Hamden   On 01 Jan 2015  Viewed: 1,143
  • base64string
  • memorystream
  • c#

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#

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: 1,654
  • xml
  • xdocument
  • asp.net
  • c#

Convert xml, json to class in asp.net c# by one click

Convert XML or JSON into a class by using visual studio is as easy as just copy and two clicks, never matter how big or how complicated is our XML or JSON. In this article we will create some dummy XML and json and will try to convert them into class without writing a single property manually. It does not create 100% correct data type but created all the properties for. Say we have an XML or... By Ali Adravi   On 20 Dec 2014  Viewed: 693
  • xml
  • json
  • c#
  • object
  • asp.net

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#

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#

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 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#

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

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

Method overloading in C# with example

Method overloading means having different methods with same name but with different types of parameters or number of parameters also known as static polymorphism. In this article we will try to understand what is method overloading and how we can overload a method with example. Suppose we have a class Calculate which can have a method Add by using two integers, two double, any number of... By Hamden   On 19 Jul 2013  Viewed: 1,378
  • overloading
  • c#
  • oops

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#

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

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#

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

Convert string to an enum type in .net

Sometime we need to convert string to an enum type, say I need to store my enum value into viewstate then we cannot store enum or any object to viewstate so converted that to string and store it, and on postback need to read the viewstate and convert to enum, so how to convert a string into enum? We will see this in this article. Let’s say our enum is like this: Public enum ReportType ... By Hamden   On 21 May 2013  Viewed: 918
  • enum
  • c#
  • asp.net
  • oops
12