Wednesday, February 16, 2022

tsc.ps1 is not digitally signed error in typescript

 If you want to compile your typescript file  and getting blow error the solution for this error is below. 



Solution :- 

Open you PowerShell window in administrator mode.


You can run this in PowerShell command.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned


Thank you ! Hope it is help

Thursday, February 10, 2022

FizzBuzz In C# with Visual studio 2022

 “FizzBuzz” is an interview question asked during interviews to check logical skills of developers.

For Demonstration, we will print number starting from 1 to 100. When a number is multiple of three, print “Fizz” instead of a number on the console and if multiple of five then print “Buzz” on the console. For numbers which are multiple of three as well five, print “FizzBuzz” on the console. I am using visual Studio 2022.

Create New project in Visual Studio 2022.My solution is look like as below screen.


My solution and project name is "Practice".

Add new class with Method

 public static void fizzBuzz(int n)
        {
            for (int i = 1; i <= n; i++)
            {
                if (i % 3 == 0 && i % 5 == 0)
                {
                    Console.WriteLine("FizzBuzz");
                }
                else if (i % 3 == 0)
                {
                    Console.WriteLine("Fizz");
                }
                else if (i % 5 == 0)
                {
                    Console.WriteLine("Buzz");
                }
                else
                {
                    Console.WriteLine(i);
                }
            }
        }

Now it is final time to put code in the Program.cs 

using Practice;

Console.WriteLine("Hello, World!");

Console.WriteLine("Please enter your number ");
int n = Convert.ToInt32(Console.ReadLine());

Result.fizzBuzz(n);

Output are as below



Thank you Hope it is help you.




 

Tuesday, February 1, 2022

C# Questions and answers

 1) What's the difference between Invoke() and BeginInvoke() on delegate?

The answer are as below 

  • Delegate.Invoke: Executes synchronously, on the same thread.
  • Delegate.BeginInvoke: Executes asynchronously, on a threadpool thread.
  • Invoke blocks the caller until the scheduled action finishes.
  • When you use BeginInvoke your loop is going to run super fast since BeginInvoke returns right away. This means that you're adding lot and lots of actions to the message queue. You're adding them much faster than they can actually be processed. This means that there's a long time between when you schedule a message and when it actually gets a chance to be run.
2) How to check a thread status.
Ans:- A Thread class is responsible for creating and managing a thread in multi-thread programming. It provides a property known as IsAlive to check if the thread is alive or not. Or in other words, the value of this property indicates the current execution of the thread.

Syntax:
public bool IsAlive { get; }

// C# program to illustrate the
// use of IsAlive property
using System;
using System.Threading;

public class GFG {

// Main Method
static public void Main()
{
Thread thr;

// Get the reference of main Thread
// Using CurrentThread property
thr = Thread.CurrentThread;

// Display the current state of
// the main thread Using IsAlive
// property
Console.WriteLine("Is main thread is alive"+
" ? : {0}", thr.IsAlive);
}
}

Output:Is main thread is alive ? : True

3) How to subscribe to and unsubscribe from events In C#.

Ans:-