Saturday 14 January 2017

Abstract in c#

ABSTRACT :-The purpose of abstract class is to provide a common definition of based class that multiple derived classes can share, and can be used only as a based class and never want to create the object of this class.Any class can be convert in abstract class by adding abstract modifier to to.

Some key point of  an abstract class and method are:-

  1. An abstract class can not be instantiate.
  2.  An Abstract class can have access modifiers like public, protected, internal with class members. But abstract members cannot have private access modifier.
  3. An abstract class must have an abstract method.
  4. An abstract method is implicitly a virtual method.
  5. The class containing at least one abstract method must be declared abstract.
The purpose of an abstract class is to provide basic functionalities that multiple derived classes can share and override.
  
Example:-
       class Program
    {
        public abstract class university
        {
            public abstract void MCA();
            public abstract void MBA();
            public void Durination()
            {
                Console.WriteLine("Post Graduate fees Structure");
            }

        }
        public class WBTU:university 
        {
            public override void MCA()
            {
                Console.WriteLine("Fees is 250000");
            }
            public override void MBA()
            {
                Console.WriteLine("Fees is 5000000");
            }

        }
        public class BHU : university
        {
            public override void MCA()
            {
                Console.WriteLine("Fees is 350000");
            }
            public override void MBA()
            {
                Console.WriteLine("Fees is 450000");
            }
        }
            static void Main(string[] args)
        {
            university objUni = new WBTU();
            objUni.Durination();
            objUni.MBA();
            objUni.MCA();
            objUni = new BHU();
            objUni.MBA();
            objUni.MCA();
            Console.ReadLine();
            

        }
    }

Note:-From above example we have make one abstract class university and two abstract methods MCA and MBA. WBTU and BHU both are override university course fee.
University course common for both WBTU and BHU so university method MCA and MBA is abstract.
WBTU and BHU inherited abstract method so university method must be override here.

Thursday 12 January 2017

Fibonacci Series using for loop in C#

using System;


    class Fibonacci
    {
        static void Main()
        {
            Console.WriteLine("Enter First No");
            int num1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter Second No");
            int num2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter no of iteration you need");
            int range = Convert.ToInt32(Console.ReadLine());
            int result = 0;
            Console.WriteLine(num1);
            Console.WriteLine(num2);
            for (int i = 0; i <= range; i++)
            {

                result = num1 + num2;
                Console.WriteLine(result);
                num1 = num2;
                num2 = result;
            }
            Console.ReadLine();

        }
    }
 Dry run: 
DRY RUN
NOI=10 num1=1 num2=2
No Of Iteration num1 num2 Result
1 1 2 3
2 2 3 5
3 3 5 8
4 5 8 13
5 8 13 21
6 13 21 34
7 21 34 55
8 34 55 89
9 55 89 144
10 89 144 233
 Output:-Enter First No
1
Enter Second No
2
Enter no of iteration you need
10
1
2
3
5
8
13
21
34
55
89
144
233
377

Loop: - Loop is mechanism which used to execute your statement till the condition become false.
Further loop can categories into two. 1)Range Based and 2)Condition Based.




                                                                                                                                          

Range Based:- In this case user/developer must aware range of iteration.  
Iteration 0 to 10.in this scenario we will go for loop.
For Loop:- This loop repeatedly executes  a group of  statements as long as a condition not become false.
Syntax:-for( int i=0;i<10;i++ or--)
{ Operation
}
For loop consist three importance parts.
1)      Initialization
2)      Condition
3)      Increment/ decrement.
Eg:-
( int i=0;i<10;i++ or--)
1       2            3


 .

















Tuesday 10 January 2017

Check Whether an Alphabet is Vowel or Consonant using C#

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

namespace SwitchCase
{
    class Switch
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a Character");
            char ch = Convert.ToChar(Console.ReadLine());
            switch (ch)
            {
                case 'a':
                    Console.WriteLine("Vowel");
                    break;
                case 'e':
                    Console.WriteLine("vowel");
                    break;
                case 'i':
                    Console.WriteLine("Vowel");
                    break;
                case 'o':
                    Console.WriteLine("Vowel");
                    break;
                case 'u':
                    Console.WriteLine("Vowel");
                    break;
                default:
                    Console.WriteLine("consonant");
                    break;
                             
                    }
            Console.ReadLine();
        }
    }
}

How to get logged in User's Security Roles using Java Script in dynamic CRM 365.

 function GetloggedUser () {     var roles = Xrm.Utility.getGlobalContext().userSettings.roles;      if (roles === null) return false;      ...