Posts

Showing posts from 2018

Multiple Inheritance in C#

In this article we are going to see, Inheritance in C#. So, What is an Inheritance in C#? An Inheritance is a concept or approach where one type can be derived from other types Just like a son gets his DNA from his parents. In c#, we can derive a type from other types. So the child type can inherit its parent type members such as Methods, Property, etc. Now, we will see Multiple Inheritance where a class can derive from more than one type. But for that, a class has to derive from Interfaces. Because Interfaces supports multiple Inheritance, a normal class derived from only one Class and multiple interfaces. (Type means Classes, Interfaces, and Abstract classes)Following is a simple program to understand it. Code Snippet:- public interface Interface1 { /// <summary> /// Abstract method declaration /// </summary> /// <param name="_input"></param> void WhatUgot(int _input); } public interface Interface2 { /// <summary> /// Abstract...

Single Inheritance in C#

In this article we are going to see, Inheritance in C#.So, What is an Inheritance in C# ? An Inheritance is a concept or approach where one type can derived from other type. Just like a son gets his DNA from his parents. In c#, we can derive a type from other type. So the child type can inherit its parent type members. ( Members mean Methods,Property etc.)Now , we will see Single Inheritance where a class and inherit only one class. A class can not be derived from more than one class that’s why we called it as Single Inheritance. (Type means Classes,Interfaces and Abstract classes).Following is a simple program to understand it. Code Snippet:- /// <summary> /// Abstract class /// </summary> public abstract class AbsClass { /// <summary> /// Abstract method declaration /// </summary> /// <param name="_input"></param> public abstract void WhatUgot(int _input); } /// <summary> /// Non Abstract Clas...

RunTime Polymorphism in C#

In this article we are going to see, polymorphism in C#.So, What is a polymorphism in C# ? As the polymorphism word itself describes its defination which means multiple forms.Poly means "Multiple” or “Many” and Morphisum means “changing” or “converting”.So in C# , polymorphism works in two scenario which are Run time and Compile time. Now we will see Run time polymorphism which is Method Overriding. Method Overriding is a concept or an approach where we can create Methods with same name and same signature. (Signature means number of passed argument/parameters considering with their data type and sequence)Following is a simple program to understand it. Code Snippet:- /// <summary> /// Parent Class /// </summary> public class ClassA { /// <summary> /// Virtual Method /// </summary> /// <param name="_input"></param> public virtual void WhatUgot(int _input) { Console.WriteLine("This is Original Virtual Method"); ...

Compile Time Polymorphisum in C#

In this article we are going to see, polymorphism in C#.So, What is a polymorphism in C# ?As the polymorphism word itself describes its defination which means multiple forms.Poly means Multiple” or “Many” and Morphism means “changing” or “converting”.So in C# , polymorphism works in two scenario which are Run time and Compile time.First we will see Compile time polymorphism which is Method Overloading. Method overloading is an concept or approach where we can create Methods with same name but different signature. (Signature means number of passed argument/parameters considering with their data type and sequence) Following is a simple program to understand it. Code Snippet:- /// <summary> /// class with Overloaded method with different signature but with same method name. /// </summary> public class CompileTimePolyMorph { /// <summary> /// Method with integer as input parameter /// </summary> /// <param nam...

Abstraction in C#

In this article we are going to see, Abstraction in C#.So, What is an Abstraction in C#? Abstraction is one of the key concepts of Object-Oriented Programming which is used to hide the complexity of data from users or consumers. There are several ways to achieve it, like using private access modifier, Interfaces and Abstract classes. For example, in the case of WCF services we provide Interfaces to consumers not an actual class. Because the actual class might have various methods and data which is useless and confusing for the consumer. Following is a simple program to understand it. Code Snippet:- public abstract class Animal { // Open to Consumer or user public abstract void Eat(string _food); public void Sounds(string _voice) { Console.WriteLine("And sounds like " + _voice); } } public class Lion: Animal { public override void Eat(string _food) { Console.WriteLine("Lion likes to eat " + _food); } } public class AbstarctionDemo { static ...

How to Convert DataTable into List in C# ?

In this article, we are going to convert DataTable into a List in C#. There are three ways to do it. We will see in following simple program how to do it. The program is self-explanatory in the form of code comments. Code Snippet:- using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace BlogsProgram { public class Program { // Creating an Entity class for Employee public class Employee { public int EmpID { get; set; } public string EmpName { get; set; } public string City { get; set; } } public static void Main(string[] args) { // Creating Object of Program class to access its Members Program _obj_Program = new Program(); // Defined Tabble as "Employee". DataTable dt = new DataTable("Employee"); // ...

How to Transpose DataTable in C# ?

In this article we are going to see, How to transpose DataTable in C#? It means we are going to convert DataRow into DataColumn and DataColumn intoDataRow.Following is the simple and self-explanatory example in the form of code comment. Code Snippet:- using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BlogsProgram { public class TansposeDataTableClass { public void TransposeDataTable() { // Defined Table as "Employee". DataTable dt = new DataTable("Employee"); // Defined "EmpID" column as Integer Datatype. dt.Columns.Add("EmpID", typeof(Int32)); // Defined "EmpName" column as String Datatype. dt.Columns.Add("EmpName", typeof(string)); // Defined "EmpRank" column as String Datatype. dt.Columns.Add(...

Importing and Indexing .CSV file in solr

1) Download the latest version of Apache Solr from the following location: http://lucene.apache.org/solr/downloads.html 2) Once the Solr zip file is downloaded unzip it into "C:\\Program Files" folder. The extracted folder will contain few subfolders such as bin, Contrib , dust, docs, example, license, server etc. 3) Now open command prompt in administrative mode and goto bin directory of solr to start it.Ex:- C:\Program Files\solr-6.0.0\bin > solr start And to stop solr C:\Program Files\solr-6.0.0\bin > solr stop -all 4) Now its time to create Core-Admin to import, index, and search data. For that we have to use the following commands. Ex:- C:\Program Files\solr-6.0.0\bin >solr create -c jcg -d basic_configs 5) We can see the following output in the command window.Creating new core 'jcg' using command: http://localhost:8983/solr/admin/cores?action=CREATE&name=jcg&instanceDir=jcg { "responseHeader":{ "status":0, ...

Encapsulation in C#

In this article we are going to see, Encapsulation in C#. So, What is an Encapsulation in C#? The answer is very simple, Encapsulation is nothing but wrapping up of data or members in order to protect them or secure them. Following is a simple program to understand it. Code Snippet:- using System; public class Class1 { public void Method1() {  Console.WriteLine("Calling this Method1 by using Object of Class1.Becauseit is non static."); } } public static class Class2 { public static void Method2() { Console.WriteLine("Calling this Method2 by using name of Class2. Because it is static."); } } public class Encapsulation { public static void Main(string[] args) { // Creating object of Class1 Class1 object1 = new Class1(); // Calling Method/Data Member of Class1 using its object. object1.Method1(); // Calling Method2 using Class2 name because it is static.It means, it is sharable. Class2.Method2(); Console.ReadLine(); } } In the abo...