How to find the factorial of a number using c#

There are two approaches you can try for the above scenario one is with recursion and another one is using for loop.



        

  static void Main(string[] args)
        {
           int rslt= FactorialWithoutR(5);
           Console.WriteLine("Factorial is :{0}", rslt);
        }

        public static int Factorial(int limit)
        {
            // Using Recursion
            if (limit == 0)
            {
                return 1;
            }
            return limit * Factorial(limit - 1);
        }

        public static int FactorialWithoutR(int limit)
        {

            int factorial = 1;
            for (int i = 1; i <= limit; i++)
            {
                factorial = factorial * i;
            }
            return factorial;
        }

How to create Fibonacci series for the given limit using C#

Please find the solution for the same below.




















        

  static void Main(string[] args)
        {
            Fibonacci(10);
        }

        public static void Fibonacci(int limit)
        {
            // Method 1
            int a = 0; int b = 1; int c=0;
            Console.WriteLine("Method 1");
            Console.WriteLine("Fib Series : {0},{1}", a, b);
            for(int i = 2; i < limit; i++)
            {
                c = a + b;
                Console.Write("{0} ",c);
                a = b;
                b = c;

            }

            // Method 2
            int[] fibnArray = new int[limit];
            fibnArray[0] = 0;
            fibnArray[1] = 1;

            for (int i = 2; i < limit; i++)
            {
                fibnArray[i] = fibnArray[i - 2] + fibnArray[i - 1];
            }

            string fib1 = "";
            fibnArray.ToList().ForEach(x => { fib1 = fib1 + x.ToString() + ","; });
            Console.WriteLine("\n Method 2");
            Console.WriteLine("Fibonacci Series " + fib1);

            //Method 3
            Console.WriteLine("Method 3");
            Recurring(0, 1, 1, 10);
            // Method 4
            List fibnList = new List();
            for (int i = 0; i < limit; i++)
            {
                if (i == 0 || i == 1)
                {
                    fibnList.Add(i);
                }
                else
                {
                    fibnList.Add(fibnList[i - 2] + fibnList[i-1]);
                }

            }
            string fib = "";
            fibnList.ForEach(x => { fib = fib + x.ToString() + ","; });
            Console.WriteLine("\n Method 4");
            Console.WriteLine("Fibonacci Series " + fib);
            Console.ReadLine();
        }

        public static void Recurring(int a,int b,int counter,int limit)
        {
            if (counter < limit)
            {
                Console.Write(a);
                int c = a + b;
                counter = counter + 1;
                Recurring(b, c,counter , limit);
            }
                    
        }

How to convert a List as comma separated string using Linq, C#

Here I am resolving the problem with different approaches using C#


        

   static void Main(string[] args)
        {
            ListCommaSepearted();
        }

        public static void ListCommaSepearted()
        {

            List lstString = new List()
              {
                  "Coder",
                  "Juggernaut",
                  "Blog"
              };

            // Method 1
            var k = "";
            foreach (var item in lstString)
            {
                k = k+ item + ",";
            }
            k= k.Remove(k.LastIndexOf(','));
            
            // Method 2

            var str = string.Join(",",lstString);
            var q = "";
 
            //Method 3
            lstString.ForEach(delegate(string item)
            {
                q = q + item + ",";
            });

            //Method 4
            var p = "";
            lstString.ForEach(x =>
            {
                p = p + x + ",";
            });

            Console.WriteLine("Coma : {0} ", p);
            Console.ReadLine();
        }

how to convert uppercase to lowercase and lowercase to uppercase of given string using c#

Here I am solving the problem using C# programming language


        

   static class Program
    {
        static void Main(string[] args)
        {
            CaseConvertion("Coder Juggernaut Blog");
        }

        public static void CaseConvertion(string input)
        {

            string newString = "";
            foreach (char item in input)
            {
                if (char.IsLower(item))
                {
                    string upper = item.ToString().ToUpper();
                    newString = newString + upper;

                }
                else if (char.IsUpper(item))
                {
                    string lower =  item.ToString().ToLower();
                    newString = newString + lower;
                }
                else
                {
                    newString = newString + " ";
                }
               
            }

            Console.WriteLine("Conerted  Name : {0} ", newString);
            Console.ReadLine();
        }
    }

How to find the count of numbers,letters and special character from the given string C#

This is a common interview question. here I am going to solve it using C# programming language.

 




       

 static class Program
    {
        static void Main(string[] args)
        {
            FindCount("abc2D$%@");
        }

        public static void FindCount(string input)
        {
            int num_count = 0;
            int letter_count = 0;
            int symbol_Cont = 0;

            foreach (char item in input)
            {
                if (char.IsNumber(item))
                {
                    num_count = num_count + 1;

                }
                else if (char.IsLetter(item))
                {
                    letter_count++;
                }
                else
                {
                    symbol_Cont++;
                }
            }

            Console.WriteLine("Num Count: {0},letter Count: {1} symbol Count: {2} ",
             num_count, letter_count, symbol_Cont);
            Console.ReadLine();
        }
    } 


What is the difference between == and === in javascript

In javascript for comparing the equality we can use both == and === depends on our specific development criteria. So it's better to know the difference between them.
please check the gif image attached



Sort array in ascending or descending order using sort function

Array :

let k=[1,3,11,2,33,22]

k.sort()

Result :
[1,11,2,22,3,33]

Here the array just sorted based on the ASCI values, so how to make it such way that it can return the array in ascending sort order.

k.sort((a,b)=>{return a-b})
use the fat arrow function
Result : [1,2,3,11,22,33]

descending sort order.
k.sort((a,b)=>{return b-a})

Result : [33,22,11,3,2,1]

Use the below tool to try ES6 javascript

https://stephengrider.github.io/JSPlaygrounds/


Microsoft.Office.Interop.Excel dll is missing in visual studio 2015, quick fix

If you have newly installed visual studio 2015, you might not be having the Microsoft.office related dlls. So your existing project or new project in which you are using Microsoft  office related dlls you may face the library reference issues. to avoid these things you have to install micorsoft office tools for VisualStudio.
you can get the installer  here : download
Once you have done with the installation you can check office related dlls in this folder
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Visual Studio Tools for Office\