Saturday, 28 March 2020

Private Constructor in C#
In this article, you will see the details about Private Constructor.

Private Constructor is a special instance constructor, and it is useful in classes that contain only static members. 
If a class contains one or more private constructors and no public constructors, then the other classes are not allowed to create an instance for that particular class except nested classes.

Private Constructor in C#

Private Constructor in C# In this article, you will see the details about Private Constructor. Private Constructor is a special instance con...

Tuesday, 10 March 2020



The code snippet is given as below.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustomExceptionInCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                int res = checkAGE();
                Console.WriteLine(res);
                Console.ReadLine();
            }
            catch (CustomEx_AGE ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        static int checkAGE()
        {
            Console.WriteLine("Enter AGE:");
            int age = Convert.ToInt32(Console.ReadLine());
            if (age<18 18="" :="" above="" age="" base="" be="" class="" customex_age="" exception="" msg="" new="" pre="" public="" return="" should="" string="" throw="">

How to create Custom Exception in C# ?

The code snippet is given as below. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System...

Tuesday, 3 March 2020



Using throw statement-


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace throw_throwex
{
    class Program
    {
        static void Main(string[] args)
        {
            //difference between throw and throw ex in c#
            try
            {
                int x = calc(5, 0);
                Console.WriteLine(x);
                Console.ReadLine();
            }
            catch (Exception)
            {
                throw;
            }
        }
        public static int calc(int a, int b)
        {
            return a / b;
        }
    }
}
Output:


Using throw ex statement-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace throw_throwex
{
    class Program
    {
        static void Main(string[] args)
        {
            //difference between throw and throw ex in c#
            try
            {
                int x = calc(5, 0);
                Console.WriteLine(x);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static int calc(int a, int b)
        {
            return a / b;
        }
    }
}

Difference between throw and throw ex in c# with simple example

Using throw statement- using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.T...

 

Technical Talks © 2015 - Designed by Templateism.com, Distributed By Blogger Templates