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
  6. 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