Learn C#.NET, ASP.NET MVC 5,ASP.NET Core that you can increase your knowledge and coding to develop the real-time project.


Wednesday, August 1, 2018

What ASP.NET Core Is And Advantages Of Using It


In this article, we will learn what ASP.NET Core is and what are the advantages of using ASP.NET Core. We will also see how to set up ASP.NET Core Environment for beginners and professionals in a step by step manner.

ASP.NET Core


Introduction to ASP.NET Core:

This article are designed for beginners and professionals who want learn how to build ASP.NET Core web applications step by step.

ASP.NET Core is a open source, cross platform and high performance web framework to build the web application.which can be run on Windows, Mac or Linux operating system. ASP.NET Core framework is combination of MVC and Web API in single web framework.

  • Developer can build modern, cloud-optimized, IoT, Mobile Backends application using ASP.NET Core framework.
  • We can develop and run ASP.NET Core application on Windows, Mac, Linux operating system. 
  • We can also deploy our application on cloud or run on-premises.
  • ASP.NET Core run on .NET Core framework or .NET Standard framework.
Prerequisites:
  • Basic knowledge of C# 
  • Visual Studio
  • Object Oriented Programming concepts

Advantages of ASP.NET Core:

ASP.NET Core


  • Fast: It is lightweight, high-performance web framework.
  • Integration of Modern UI Framework: ASP.NET Core support modern, Client side framework like AngularJs, ReactJs and React with Redux etc. ASP.NET framework supports client side framework templates like AngularJs, ReactJs and React with Redux etc.
  • Hosting: It has ability to host on IIS, Apache, Docker or Self Hosting.
  • Cross Platform: ASP.NET Core web application can run on Windows, Mac, Linux development tools. 
  • Support Built In Dependency Injection: It support built in Dependency Injection.
  • Supports Modular: It support modular HTTP request.
  • Open-Source: It is open-source web framework.
  • Side-by-side app versioning: ASP.NET Core runs on .NET Core which supports simultaneous running of multiple versions of applications.
  • A unified story for building web UI and web APIs.

ASP.NET Core Environment Setup:

To develop ASP.NET Core web application you need to installed in your system as follow
  • .NET Core SDK
  • .NET Core Runtime
  • Integrated Development Environment (IDE)
ASP.NET core is part of .NET Core SDK. You need to install .NET Core SDK in your system.
If you work with Visual Studio 2015 then you can download .NET Core 1.0 and Same of .NET Core Runtime 1.0 version to support VS 2015. For the different version of .NET Core SDK and .NET Core, Runtime click here Download different version of .NET Core SDK

ASP.NET Core web application you need to install:
  • .NET Core SDK:  
Download .NET Core SDK for the different platform from here Download .NET Core SDK from Microsoft website. After clicking on the URL you need to select the operating system you work and download.

ASP.NET Core


  • .NET Core Runtime:  
Download .NET Core Runtime for a different platform from download .NET Core Runtime.

ASP.NET Core


IDE:

You can use either Visual Studio 2015 Or Visual Studio 2017 to develop .NET Core web application.

Visual Studio 2015

If you work with Visual Studio 2015 then you can download .NET Core 1.0 and Same of .NET Core Runtime 1.0 version to support VS 2015 as shown in the above links for .NET Core SDK and .NET Core Runtime.

We will use Visual Studio 2017 to develop .NET Core web application.

Visual Studio 2017 - How to Install Visual Studio 2017 ?

You can download visual studio 2017 for VS Installer 2017. Click on this link to download the visual studio 2017 to work with .NET Core.

Step 1

ASP.NET Core

Once you open the given link in a new tab then you will open the page as above. Then click on ‘Free download’ link. Then the VS 2017 installer will get the download. After that click on Visual Studio 2017 installer and run as administrator. Then, click on the 'Continue' button.

Step 2

Select the 'ASP.NET and Web development' template for Web Development OR '.NET desktop development' for Windows Forms and console app' to develop WinForm and console application using C#, F#, VB etc. from Workloads tab as in the image below.

ASP.NET Core


Step 3

Select the Individual components as per the requirement.

ASP.NET Core


Step 4

Select your language packs like 'English' from Language packs tab or you can select any language as per your requirement.

ASP.NET Core



 Step 5

Click on 'Launch' button from Visual Studio Installer.

ASP.NET Core


I hope this article will help you to understand the concepts of what is ASP.NET Core, Advantages of ASP.NET Core and ASP.NET Core Environment Step by Step.

References:






Share:

Saturday, July 7, 2018

Polymorphism In C# With Real Time Example


We will learn about polymorphism in c# with an example and Type of polymorphism in c# in this article. That will help you understand the concepts of polymorphism in c# with real time example for fresher as well as experienced people.

What is polymorphism?
It is used to one object behaving as multiple forms. Or polymorphism means one name many forms.

Real Time Example: 
1. A person behaves as an employee in the office,  that the same person behaves as a father in the house, that the same person behaves as a customer in the shopping malls.

Polymorphism In C# With Real Time Example










Description: a person is one object. It behaves as an employee in office as well as the father in the house. So the concept is here one name many forms.

Type of polymorphism

  • Compile time polymorphism / Static polymorphism
  • Run time polymorphism / Dynamic polymorphism





  • Static or Compile time polymorphism:
In the compile time polymorphism compiler know which method is going to call at compile time called compile-time or Static polymorphism.
The static or compile time polymorphism can be achieved by using “function overloading”.Where the compiler know which overloaded method is going to call at compile time.
function overloading means the same method name but the type of parameter should be different.

Example 1: This is the basic example to understand the concept of method overloading.
using System;

namespace MethodOverloading
{
    class Program
    {
        // Method Overloading
        public int Add(int x, int y)
        {
            return x + y;
        }
        public int Add(int x, int y, int z)
        {
            return x + y + z;
        }
        static void Main(string[] args)
        {
            Program prog = new Program();
            Console.WriteLine("Addition of Number is {0}", prog.Add(10, 20));

            Console.WriteLine("Addition of Number is {0}", prog.Add(10, 20, 30));

            Console.ReadLine();
        }
    }    

}

Share:

Monday, May 28, 2018

What is an abstract class in c#

What is an abstract class?  
abstract class in c#


  •  An abstract class can contain abstract and non-abstract member.
  •  An abstract class can be used as a base class 
  •  An abstract method does not have body/definition.
  •  An abstract class cannot be marked as a sealed class.
  •  We can not create an object of abstract class.
  •  We can create abstract class and method by using "abstract" keyword.
  •  We can not provide the static keyword to the abstract method.
  •  Once we inherit an abstract class in derived class then we must provide definition to the abstract member.
  • We can implement the abstract method by using “override” keyword.
  
Syntax: Creating abstract class.
<modifier> abstract class <class_name>
{
// member
}

Syntax:  Creating the abstract method.

<modifier> abstract return_type <method_name>(<parameter_list>);

Example: Simple example to understand the basic concept of abstract class and abstract method.

using System;
namespace AbstractClassProject
{
    public abstract class DiscountedCustomer
    {
        public int CustId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int Price { get; set; }
        public int Discount { get; set; }
        
        public string GetCustomer() // Non Abstract Method
        {
            return this.FirstName + " " + this.LastName;
        }
        public abstract int CalculateDiscount(); // Abstract Method       
    }
    public class Customer:DiscountedCustomer
    {        
        public override int CalculateDiscount()
        {
            return this.Price * this.Discount/100;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Customer customer = new Customer() {
                CustId=101,
                FirstName="Mauli",
                LastName ="Gadewar",
                 Price = 500,
                 Discount =20
            };
            Console.WriteLine("Customer Full Name is {0}", customer.GetCustomer());
            Console.WriteLine("Total Price is {0}", customer.Price);
            Console.WriteLine("Customer Discount Rs is {0} ", customer.CalculateDiscount());
            Console.ReadLine();
        }
    }
}

More information please watch video as follow:




Share:

Sunday, May 27, 2018

Constant Vs Readonly In C#

Difference between constant and readonly in C#
difference between variable and constant in c#


1. constant:
  •  It is used to store the constant value.
  •  It is compiled time constant.
  •  We can not modify/change the constant value.
  •  The Constant variable can by access by using the class name.
  •  We must assign the value to the constant variable at the declaration time.
  •  We can not provide the static keyword to the constant variable.
  •  We can not access the constant variable by using object of the class.


2. Readonly keyword:
  •  It is used to store the constant value.
  •  It is run time constant.
  •  We can modify/change the readonly variable value in the constructor of the class.
  •  The readonly variable can be accessed by using object of the class or class name.
  •  we can provide the static keyword to the readonly variable.
  •  We can access the readonly variable by using object of the class or class name.


Example: 

using System;
namespace CSharpProject
{
    class Program
    {
        public const string strConnection = "Test Connection";
        //public static readonly double Pi = 3.1; // we can define static keyword to the readonly variables
        public  readonly double Pi = 3.1;
        public Program()
        {
            Pi = 3.14;
        }               
        static void Main(string[] args)
        {
            Program pro = new Program();
            Console.WriteLine(pro.Pi); // Calling not static readonly variable by using object of class.
           // Console.WriteLine(Program.Pi);// calling static readonly keyword by using class name.
            Console.WriteLine(Program.strConnection);
            Console.ReadLine();
        }
    }
}



More Details watch the following video on the same:







Share:

Sunday, May 6, 2018

About Me

Shrimant Telgave is a Software Developer, Author, Blogger having experience in Design, developing and maintaining large-scale applications. He is a technology aggressive and blogs on his own website www.programmingwithshri.com as well as www.c-sharpcorner.com

He has a good experience in C#, ASP.NET, ASP.NET MVC, SQL Server, Web Services, WCF, Entity Framework, LINQ, ADO.NET, JavaScript, jQuery. He did his master degree from Pune University. He did Microsoft .NET training from Hyderabad. 

He keeps an eye on new technologies and implements them. Use the best way and optimized approaches to solving the problem, issues and ease the process by using well equipped and standard techniques to boost the performance of the applications.

You can find out me on following links:

Share:

C#.NET Tutorials [step by step]

Share:

Friday, May 4, 2018

[C#] - What is Delegates in C# Example | Use of Delegates in C# | Type of Delegates in C#


Delegates in C#

In this article, we will learn Delegate in C#.NET with example, Type of delegate in c#  [real time] example and Anonymous method. I will explain Singlecast Delegate and Multicast Delegate in c#.net with an example [step by step].

What is the Delegate?
It is type safe function pointer. Which hold the reference/address of the method.

Type safe function means
1. The return type of delegate should be the same as the return type of method.
2. The parameter type of delegate should be the same as the parameter type of method.

In order to work with the delegate, we have to follow three steps as follow.

Step-1: Define a Delegate.
[<modifier>] delegate void|type(return_type) <delegate_name>([<parameter list>]);
e.g:
  1. public delegate void MessageDelegate()

Step-2: Instantiating the delegate or binding method to the delegate instance.
<delegate_name> object_name = new <delegate_name>(<method_name>);
OR
<delegate_name> object_name = <method_name>;
e.g:
  1. // Step-2: Instantiating the Delegate.
  2. MessageDelegate message = new MessageDelegate(Email.DisplayMessage);

Note: <method_name> If the method is static then, We call by using the class name. If the method is non-static then we can call that method by using object of the class.
There is two way to instantiating the delegate as mentioned above. I will go through one by one in the example so that you can understand better.
Step-3: Invoking the delegate.
<delegate_object>.Invoke(<parameters>);
OR
<delegate_object>(<parameters>);
e.g: 
  1. // Step-3: Invoking the delegate
  2. message.Invoke();

Note: <parameters> We can pass parameters as we mentioned to the respective methods.
Example 1: This is the very simple example to understand the basic concepts of the delegate.

Step-1: Define a delegate
Note: we can define the delegate inside the namespace or class.
  1. // Step-1: Define a Delegate
  2. public delegate void MessageDelegate();
  3. public delegate string EmailDelegate(string strEmail);


Create class having names like "Email" and two methods as follow.


  1. public class Email
  2. {
  3. public static string GetEmail(string strEmail)
  4. {
  5. return "Your Email Id is "+strEmail;
  6. }
  7. public static void DisplayMessage()
  8. {
  9. Console.WriteLine("Welcome to CSharp Corner");
  10. }
  11. }


Step-2: Instantiating the delegate 


  1. // Step-2: Instantiating the Delegate.
  2. EmailDelegate email = new EmailDelegate(Email.GetEmail);
  3. MessageDelegate message = new MessageDelegate(Email.DisplayMessage);

The second way to the binding method to the delegate instance.

  1. //OR
  2. // Step-2: Binding method to the Delegate instance.
  3. EmailDelegate email = Email.GetEmail;
  4. MessageDelegate message = Email.DisplayMessage;



Step-3: Invoking the delegate or binding method to delegate instance.



  1. // Step-3: Invoking the delegate
  2. string strEmail= email.Invoke("shrimantvt@gmail.com");
  3. Console.WriteLine(strEmail);
  4. message.Invoke();


We can invoke method by using "Invoke()" method or we can pass direct parameter to the delegate instance as following.

  1. // Step-3: Invoking the delegate second way
  2. email("shrimantvt@gmail.com");
  3. message();

Program Code: 

  1. using System;
  2. namespace DelegateDemo
  3. {
  4. // Step-1: Define a Delegate
  5. public delegate void MessageDelegate();
  6. public delegate string EmailDelegate(string strEmail);
  7. public class Email
  8. {
  9. public static string GetEmail(string strEmail)
  10. {
  11. return "Your Email Id is "+strEmail;
  12. }
  13. public static void DisplayMessage()
  14. {
  15. Console.WriteLine("Welcome to CSharp Corner");
  16. }
  17. }
  18. class Program
  19. {
  20. static void Main(string[] args)
  21. {
  22. // Step-2: Instantiating the Delegate.
  23. EmailDelegate email = new EmailDelegate(Email.GetEmail);
  24. MessageDelegate message = new MessageDelegate(Email.DisplayMessage);
  25. // Step-3: Invoking the delegate
  26. string strEmail= email.Invoke("shrimantvt@gmail.com");
  27. Console.WriteLine(strEmail);
  28. message.Invoke();
  29. Console.ReadLine();
  30. }
  31. }
  32. }


Output:

Delegates in C#

Type of delegate in c#
  • Singlecast Delegate
  • Multicast Delegate
  • Singlecast Delegates:
Whenever the delegate instance refers to address of the single method. then it is said to be single cast delegate.
Example 2: This is a simple example to understand the basic concept of 'single cast delegate'.
Program Code:
  1. using System;
  2. namespace DelegateDemo
  3. {
  4. // Step-1: Define a delegate
  5. public delegate double AreaDelegate(double width,double height);
  6. public class Rectangle
  7. {
  8. public static double CalculateArea(double width, double height)
  9. {
  10. return (width*height);
  11. }
  12. }
  13. class DelegateExampleTwo
  14. {
  15. static void Main(string[] args)
  16. {
  17. //Step-2: Instantiating the delegate
  18. AreaDelegate area = new AreaDelegate(Rectangle.CalculateArea);
  19. // OR
  20. //Step-3: Binding method to delegate instance
  21. AreaDelegate area1 = Rectangle.CalculateArea;
  22. // Step-3: Invoking the Delegate by using invoke method
  23. Console.WriteLine("Using invoke method");
  24. Console.WriteLine("Area of Rectangle is {0}", area.Invoke(10.10, 20.10));
  25. // OR
  26. Console.WriteLine("-------------------------------------------------");
  27. // Step-3: Invoking the Delegate without using the invoke method
  28. Console.WriteLine("Without using invoke method");
  29. Console.WriteLine("Area of Rectangle is {0} " , area1(10.10, 20.10));
  30. Console.ReadLine();
  31. }
  32. }
  33. }

Note: In the above example the delegate instance is points to only one method like 'CalculateArea'.so that type of delegate is said to be singlecast delegate.

Output:
Delegates in C#

  • Multicast Delegate:
Whenever the delegate instance is points/refers to address of more than one method. then these type of delegate is said to be the multicast delegate.
There are two way calling the multiple methods
  • "+="
  • "+"
Step-1: Define a delegate.
Note: we can define the delegate inside the namespace or class.
  1. // Step-1: Define a delegate
  2. public delegate double RectangleDelegate(double width,double height);

Create class name like "Rectangle" having two methods like CalculateArea and CalculatePerimeter of the rectangle as follow.
  1. public class Rectangle
  2. {
  3. public static double CalculateArea(double width, double height)
  4. {
  5. return (width*height);
  6. }
  7. public static double CalculatePerimeter(double width, double height)
  8. {
  9. return 2 * (width + height);
  10. }
  11. }

Step-2: Instantiating the delegate.
  1. //Step-2: Instantiating the delegate
  2. RectangleDelegate rectangle = Rectangle.CalculateArea;
  3. rectangle += Rectangle.CalculatePerimeter;

Note: You can see the above example, there are one delegate instance points to the more than one methods.
Step-3: Invoking the delegate.
  1. // Step-3: Invoking the Delegate by using invoke method
  2. Console.WriteLine("Area of Rectangle is {0}", rectangle.Invoke(10.10, 20.10));
  3. Console.WriteLine("Perimeter of Rectangle is {0}", rectangle.Invoke(11.10, 21.22));

Program Code:
  1. using System;
  2. namespace DelegateDemo
  3. {
  4. // Step-1: Define a delegate
  5. public delegate double RectangleDelegate(double width,double height);
  6. public class Rectangle
  7. {
  8. public static double CalculateArea(double width, double height)
  9. {
  10. return (width*height);
  11. }
  12. public static double CalculatePerimeter(double width, double height)
  13. {
  14. return 2 * (width + height);
  15. }
  16. }
  17. class DelegateExampleTwo
  18. {
  19. static void Main(string[] args)
  20. {
  21. //Step-2: Instantiating the delegate
  22. RectangleDelegate rectangle = Rectangle.CalculateArea;
  23. rectangle += Rectangle.CalculatePerimeter;
  24. //Step-3: Invoking the Delegate by using invoke method
  25. Console.WriteLine("Area of Rectangle is {0}", rectangle.Invoke(10.10, 20.10));
  26. Console.WriteLine("Perimeter of Rectangle is {0}", rectangle.Invoke(11.10, 21.22));
  27. Console.ReadLine();
  28. }
  29. }
  30. }

Output:
Delegates in C#
Anonymous Method: You can simply say, It is method without having name. we can use anonymous method in delegates.it is used to write less code. It has high performance as compare to normal delegate.
Advantages:
  • Write less code
  • High performance
Example 1: This is the simple example to understand the concepts of the anonymous method.
we can take the above same example with having only one method 'CalculateArea'
Step-1: Define a delegate
  1. // Step-1: Define a delegate
  2. public delegate double RectangleDelegate(double width, double height);

Step-2: Instantiating the delegate
Note: we can see on below example there is no any method declaration. we have directly define method body to the delegate.
  1. //Step-2: Instantiating the delegate by using the anonymous method
  2. RectangleDelegate rectangle = delegate(double width, double height)
  3. {
  4. return (width * height);
  5. };

Step-3: Invoking the delegate
  1. // Step-3: Invoking the Delegate
  2. onsole.WriteLine("Area of Rectangle is {0}", rectangle.Invoke(10.10, 20.10));

Program code:
  1. using System;
  2. namespace DelegateDemo
  3. {
  4. // Step-1: Define a delegate
  5. public delegate double RectangleDelegate(double width, double height);
  6. class AnonymousMethod
  7. {
  8. static void Main(string[] args)
  9. {
  10. // Step-2: Instantiating the delegate by using anonymous method
  11. RectangleDelegate rectangle = delegate(double width, double height)
  12. {
  13. return (width * height);
  14. };
  15. // Step-3: Invoking the Delegate
  16. Console.WriteLine("Area of Rectangle is {0}", rectangle.Invoke(10.10, 20.10));
  17. Console.ReadLine();
  18. }
  19. }
  20. }

Usages of Delegate
  • It is used in Event
  • It is used in Threading
  • It is used to Callback Function
  • It is used in Multicasting
I hope you understood the basic concept of the delegate, type of delegate and anonymous method.
If you like then add your valuable feedback that will encourage me to write more articles.
Share:

Upcoming Articles/Videos

Design Pattern
SOLID Design Principles
Copyright © Programming With Shri | Powered by Shrimant Telgave Home | Disclaimer | Privacy Policy | Terms and Conditions Design by Shrimant Telgave