I have this sample code
public class MyClass
{
private static int tempKey = 0;
public MyClass()
{
this.Key = --tempKey;
}
public int Key {get; set;}
}
What does –tempkey do exactly?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It decrements
tempKeyand returns new value. Compare withtempKey--, which also decrements tempKey, but returns the original value.See Microsoft documentation here.
Where:
EDIT: This is valid for C#. Visual Basic doesn’t have this increment/decrement operator.
In Visual Basic
--tempKeyis evaluated as-1 * (-1 * tempKey)which is equal totempKey.