Wednesday, 21 November 2018

Prefix and Postfix in .NET explained in 1 minute

Using prefix in comparison will change the value before expression evaluation, where using postfix will change value after expression evaluation. Look at below example.

public static void Main()
 {
  // Prefix and Postfix example
  
  int x = 5;
  if(++x == 6)
  {
   Console.WriteLine("Using prefix will increment value before expression is evaluated.");
  }
  
  Console.WriteLine(string.Format("Value of x is {0}", x));
  if(x++ == 7)
  {
   // we will never reach this code as expression is evaluated before increment, hence x is still equal to 6
   Console.WriteLine("I am here but you will never see me in console.");
  }
  
  Console.WriteLine(string.Format("Value of x is {0}", x));
 }

You can look into example in dotnetfiddle - https://dotnetfiddle.net/txxcEa

Wednesday, 14 November 2018

Setting up environment for Angular 6

1. Check if you have npm installed by opening command and type npm -v. If you have not installed npm download it from - https://nodejs.org/en/
2. Install @angular-cli. Type npm install -g @angular/cli. -g parameter means that package will be installed globally so you can access angular cli functionality from any location.
Visit -  https://cli.angular.io/ for more info. This will enable you to create new angular project with some basic data that follows good practices.
3.  Next create new angular project. Type ng new ng-project where ng-project is name of new project you want to create. Make sure that in command line you are in folder where you want this project to appear. You can also use optional parameters like --routing or --style=scss (will use scss by default instead of css)
4. Now you open source code by typing code  (make sure you type .) in command line if you have Visual Studio Code installed (https://code.visualstudio.com/) - highly recommended
5. To run app you just create type ng -serve -o to initiate localhost server and open app in a browser. If you see error message "The serve command requires to be run in an Angular project, but a project definition could not be found" make sure you are in your angular project main folder.