Cags Posted January 16, 2006 Posted January 16, 2006 Can anybody tell me how this code can be written in c# as I don't fully understand it, thanks. If Not ((objType.Attributes And TypeAttributes.Abstract) = TypeAttributes.Abstract) Then Also am I correct in believing this is a bitwise operation? Or have I misunderstood the code. Quote Anybody looking for a graduate programmer (Midlands, England)?
Leaders snarfblam Posted January 16, 2006 Leaders Posted January 16, 2006 You are correct. And is bitwise and logical in VB. The only differences worth mentioning are that C# doesn't need the Then, and the different operators: And becomes &, = becomes ==, and Not becomes !. if !((objType.Attributes & TypeAttributes.Abstract) == TypeAttributes.Abstract) { } Quote [sIGPIC]e[/sIGPIC]
Jaco Posted January 17, 2006 Posted January 17, 2006 You are correct. And is bitwise and logical in VB. The only differences worth mentioning are that C# doesn't need the Then, and the different operators: And becomes &, = becomes ==, and Not becomes !. if !((objType.Attributes & TypeAttributes.Abstract) == TypeAttributes.Abstract) { } At the risk of being labelled a total geek, it's actually: if (! ((objType.Attributes & TypeAttributes.Abstract) == TypeAttributes.Abstract)) ;) Quote
Leaders snarfblam Posted January 17, 2006 Leaders Posted January 17, 2006 At the risk of being labelled a total geek, it's actually: if (! ((objType.Attributes & TypeAttributes.Abstract) == TypeAttributes.Abstract)) ;) Either that or this: if ((objType.Attributes & TypeAttributes.Abstract) != TypeAttributes.Abstract) { } I guess I'm just to lazy to paste my code in a code editor to check for errors. Maybe I should add a disclaimer in my signature that none of my code is tested... Quote [sIGPIC]e[/sIGPIC]
Cags Posted January 17, 2006 Author Posted January 17, 2006 Thanks for the clarification, I'd actually converted it to that final example that marble_eater gave, I just wasn't completely sure it was correct. Quote Anybody looking for a graduate programmer (Midlands, England)?
Nate Bross Posted January 17, 2006 Posted January 17, 2006 At the risk of beating a dead horse, doesn't the 'Then' keyword in VB translate into the open curly brace? and the 'End If' keywords translate to the close curly brace? (roughly) Unless the vb if was meant to be a one liner like If objTYpe = Something Then GoKillSomething() But assuming it's not wouldn't the following be closer? If objType = Something Then Becomes [csharp] if (objType == Something) { [/csharp] The reasong being in the original line of code there was no 'end if' to represend the close curly brace. Obviously not a finished piece of code, but it illustrates the point. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Leaders snarfblam Posted January 18, 2006 Leaders Posted January 18, 2006 Okay, we have too many geeks beating dead farm animals here. Arguably, one could say that the Then and End If keywords equate to curly braces since they surround the code block to be executed conditionally. Alternatively (this is my take), one can argue that while the End If is completely analogous to the closing curly brace, the opening curly brace is only implied. The Then keyword is, to an extent, a relic from a time when the only If statement was a single-line If statement (though the Then would still be a necessity for a single-line If statement). Since in VB the conditional expression isn't required to be surrounded in parentheses, the Then is necessary to syntactically separate the conditional expression and the conditionally executed code statements, hence it might be more analogous to the closing parenthesis of the conditional expression (this is consistent with single-line If statements too), or possibly the combination of the closing parenthesis and the opening brace (the opening parenthesis would be implied). Here is one interpretation of the syntactical analogy: Multi-line C# VB -------------- if( If <conditional expression> ) { Then <conditionally executed code> } End If Single-line C# VB -------------- if( If <conditional expression> ) <code> Then <code> [/Code] Take that, you effing horse. Quote [sIGPIC]e[/sIGPIC]
Nate Bross Posted January 18, 2006 Posted January 18, 2006 That's a much more indepth analysis than mine, but non-the-less I have to agree. And yes, we need to give the corps a break. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.