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. Great Article. Thank you for sharing! Really an awesome post for every one.

    IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

    JavaScript Training in Chennai

    JavaScript Training in Chennai

    ReplyDelete
  2. 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
  3. Movavi Video Editor 2022 Crack full working download is now available with all the brand new features. The new panel on the right-hand side of your timeline will help you make sure sound levels are perfect for every moment. From an easily accessible Effects menu, select one or more effects to apply them all at once with just a click. Not only this, but Movavi Video Editor Key also comes with new audio effects! Named as Flanger and Distortion. Try them out right now to discover amazing ways of altering your voice, music, or other sounds.

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

    ReplyDelete
  5. Your weblog is an unreasonable measure of flawless. i've noticed adroitly the thing I was looking. additionally, the substance energies is first rate. gratitude for the push!! Click Here

    ReplyDelete

Post a Comment