This question already has answers here:
What does the tilde mean in an expression? [duplicate]
(6 answers)
Closed 7 years ago.
intStyle = intStyle & ~(WS_MINIMIZE);
It is the first time I see this , I am trying to learn how to hook low lvl APIs to C# and make some calls , and I do not understand what this line means. Thank you guys!
It's an operation on a flag. You need to understand bitoperations (AND, OR, NOT, XOR..) for that. This line deletes the flag WS_MINIMIZE from the intStyle flagmask. More reading: Using Bitwise operators on flags , http://www.codeproject.com/Articles/13740/The-Beginner-s-Guide-to-Using-Enum-Flags.
See this for the & operator.
And this for the ~ operator
They are bitwise operators. The first one is a bitwise AND. The second one performs a bitwise complement operation.
This is a bitwise operation.
See for example http://www.codeproject.com/Articles/544990/Understand-how-bitwise-operators-work-Csharp-and-V
Related
This question already has answers here:
What does |= (single pipe equal) and &=(single ampersand equal) mean
(3 answers)
Closed 7 years ago.
Just walked through referencesource.microsoft.com (line 217)
and discovered "|=" operator. What does it means? I assume it some sort of Boolean operation- but can't get what exactly it means. Does it mean "or equal", short form like "a= a|b" ?
|= is to = what += is to =. Just a shortcut to avoid the writing of a = a | b
its a bitwise inclusive OR and assignment operator.
For details refer
https://msdn.microsoft.com/en-us/library/ms173224.aspx
You are correct. This operator is known as the "OR assignment" operator and a |= b is equivalent to a = a | b. Here is the
documentation.
This question already has answers here:
Method Call using Ternary Operator
(8 answers)
Closed 8 years ago.
I want to convert this if, else-if, can someone help me out please?
if (condition1)
response.Redirect(" some link");
else if (condition2)
response.Redirect("link 2");
I want convert above statement,but showing error at the end, required ":". Any other way i can use this?
LinkPurchase.PostBackUrl =((Condition)?string.Format("some link"):
(condition2)?string.Format("link 2));
You cannot rewrite that to the ?: operator.
You have an if-else if, not just an if-else.
Besides, you do not pick up the return values from the Redirect calls.
The usual case where you do want to rewrite to the ?: operator is:
if (condition)
something = Abc();
else
something = Xyz();
where it is natural to use instead:
something = condition ? Abc() : Xyz();
You cannot do this.
There are other answers here that inform you that the ?: operator needs the "else" part, so yes, the first problem is that you're missing that.
However, Response.Redirect doesn't return anything, so you cannot do this even with the else part.
?: is an expression, you cannot write statements (easily) with this.
Stick with the if-statements.
This question already has answers here:
Best and shortest way to evaluate mathematical expressions
(8 answers)
Evaluating string "3*(4+2)" yield int 18 [duplicate]
(13 answers)
Closed 9 years ago.
Guys I have to evaluate a mathematical expression(which is represented by a string).
Till now I had simple expressions thus the following was working fine
var result = new DataTable().Compute(STRING_HERE, null);
However now my string expression is becoming a bit more complex and the above method is starting to give errors.
Any idea of how I can handle this situation ?
Please I would like some kind of inbuilt method or function like apporach(preferably).
Not inbuild, but NCalc (http://ncalc.codeplex.com/) is a very nice library for evaluating math expressions.
This question already has answers here:
Is there a conditional ternary operator in VB.NET?
(5 answers)
Closed 9 years ago.
What is the VB.NET equivalent of the C# ? operator?
For example, how would the following code be written in VB.NET?
hp.pt = iniFile.GetValue("System", "PT").ToUpper().Equals("H") ? PT.PA : PT.SP
Historically, IIf was commonly used for that - but that does not use short-circuiting so is not quite the same. However, there is now a 3-part If:
hp.pt = If(iniFile.GetValue("System", "PT").ToUpper().Equals("H"), PT.PA, PT.SP)
that does use short-circuiting, and thus is identical to the conditional operator in C#.
You can use the If operator
hp.pt = If(iniFile.GetValue("System", "PT").ToUpper().Equals("H"), PT.PA, PT.SP)
Try using the If function like so:
x = If(condition, trueValue, falseValue)
This question is a duplicate of a question that has already been asked and answered:
Is there a conditional ternary operator in VB.NET?
here:
Dim foo as String = If(bar = buz, cat, dog)
This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
a curious c# syntax
So I've seen some code around and a few of them use a ? after the type, like this:
private Point? loc = null;
So I'm wondering if Point? is different than Point (can't put a question mark at the end of my sentence or I'll confuse you guys ... :] ). The language I'm using is C# by the way.
T? is a shorthand (in C#) for Nullable<T> - so Point? is another way of writing Nullable<Point> or example.
See sections 1.3 and 4.1 of the C# 3 language spec - and various other places, to be honest - for more details. See the docs for System.Nullable<T> for more information from the framework side of things. Or read chapter 4 of C# in Depth :) (Unfortunately it's not one of the free chapters.)
(This question is bound to be a duplicate, but I don't have the energy to find it right now.)
Point? is the same as Nullable<Point>. It allows you to assign null to value types, such as structs.
It means the type can accept its' value and null.