May someone explain the difference between suffixing and prefixing -- and ++ in C#

it seems to be very difficult to find any documentation on the difference of prefixing and suffixing – and ++ in C#, and I was wondering if anyone could explain the difference if there is any at all.

MSDN (here’s looking at you @Tiles )

It’s useful for comparisons and the sort… for example if you wanted to do a while loop that incremented something… the evaluation of the value would differ.

int i = 0;
while(i++ < 10)
{
    Console.WriteLine(i.ToString());
}

i = 0;
while(++i < 10)
{
    Console.WriteLine(i.ToString());
}

The first while loop will increment 1 to 10

The second, 1 through 9.

Personally I avoid it, and stick to the postfix version at all times. I find it more readable… otherwise you have to remember which is which. If you have to remember, prefix evaluates before it compares (pre… before), and postfix evaluates after it compares (post… after).

1 Like

That’s how I remember the distinction.

1 Like

Documentation isn’t generally necessary, because of Eric Lippert and Jon Skeet’s Stack Overflow and blog posts.

http://stackoverflow.com/questions/3346450/what-is-the-difference-between-i-and-i/3346729#3346729

Yes, but the C#/.Net documentation is all compiled in a single place on MSDN and has tools to easily find entries and related entries.

Where as… random stackoverflow members… yeah, I’ll take official documentation please.

1 Like

Eric Lippert was a C# language designer and in charge of the C# compiler until recently.

And?

So it’s a random stackoverflow member with some credentials. Which is a piece of random trivia I’d have to know when vetting his posts… information the average person wouldn’t have available to them readily without EXTRA research.

Where as again… official documentation.

You have not looked up a C# question on Stack Overflow.

Cripes, you sure talk a load of bollocks. You’ve managed to entirely dismiss tonnes of wisdom from a major contributor to the language you use. I ask you, how can you take yourself seriously after that?

Sure, I’ve looked up stuff on stack overflow. That’s not why I’m criticizing your post.

I’m criticizing it because you’re basically saying to not use documentation because stackoverflow exists, when really the OP’s issue with not finding it isn’t a lack of documentation, but the result of not going to the source of documentation.

I didn’t dismiss it what so ever.

I’m saying I’m not going to search for a random stackoverflow article for something that could be quickly and readily found on official documentation.

When the documentation fails, that’s when I go to forums and the sort. Places I’d have to VET the information from. The average person doesn’t know who those people are, so they don’t know if it’s “wisdom” or “just another crap post”.

Call me lazy, but I’ll go the easiest route FIRST where a higher level of assurance that its accurate, before falling back to the more difficult route that has a much lower rate of assurance.

If I want to know nitty gritty information about the making of the language, I’ll go to said “wise” person, because the documentation doesn’t really get into that. But to find out what the ++ operator does? Yeah… not going to waste my time. I wouldn’t ring up Stephen Hawkings to ask what Newton’s First Law is either.

How do you get anything done?

Even the most amazingly written docs only go so far in providing you with answers to things.

Your reading comprehension, it is lacking.

You wouldn’t ant to either. Hawkings would likely give you an accurate description of the first law, adjusted for quantum and relativity and who knows what else.

I’m on your side on this one. I go to the documentation first. If I can’t find it there I go to answers or SO. Saying you don’t need the documentation because we have SO is a bit bizarre.

1 Like

So apparently the Hawkings analogy nails it. Just read the links to MSDN and SO. While Lippert’s answer may be technically more correct, it’s useless for most mundane applications.

Exactly as if you’d asked Hawkings for an explaination of Newton’s first law.

Uh, he explains it really clearly what differences there are. Nobody’s saying documentation is worthless, just people are childishly ranting that only this special toy will do and everything else isn’t good enough. In reality both of course are preferable (docs + intelligent discussion).

Yeah this is wrong but no need to respond to pokes on forums :slight_smile:

Man people get heated fast here, dosnt matter docs or the SO post, the information is easy to find.

Yeah fair enough. Apologies for stoking the fire.

Honestly hippocoder…

You partook by jumping in with provoking statements like:

Totally misrepresenting what I said. And you still misrepresent it by claiming the “only this special toy will do” statement.

I clearly never said my special toy would only do, and actually said quite the contrary, that using both is the better option.

So no, I’m not apologizing to you.

I’ll apologize to OP, and any other members who feel this thread got out of hand. I was extremely caffeinated yesterday, which I don’t usually do (heart problems), and I may have gotten a bit ranty.

Either way, unfollowing thread.

I don’t require an apology nor asked for one. I’m just saying it’s really dumb all round. Not just you. It’s one of those special forum threads that I’m stupid for even partaking in.