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

Comments

  1. IOBIT Uninstaller Pro Key Crack (Latest 2022) is a tool that helps you to completely remove any unwanted programs from your pc to free up disk space and improve Iobit Uninstaller Pro 2022

    ReplyDelete
  2. Christmas Messages for Your Lover that square measure wizardly appears like Heaven to be defrayal this Christmas. Christmas Wishes For Love

    ReplyDelete
  3. Buying a printer will typically involve cost/benefit trade-offs and you'll have to determine which features are must-have, and which are merely nice-to-have. That will provide you with|provides you with} a solid overview of the assorted technologies and developments with 3D printing. A 3D printer that uses a laser to solidify resin with a excessive degree of accuracy and reliability. A 3D printer CNC machining that is easy to load filament with just about zero trouble. Pete Basiliere shares insights on how 3D printing reduces logistical costs and shortens supply instances. 3D printing funding decisions require quantitative and qualitative assessments of manufacturing choices.

    ReplyDelete

Post a Comment