Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Anybody looking for a graduate programmer (Midlands, England)?
  • Leaders
Posted

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) {
}

[sIGPIC]e[/sIGPIC]
Posted
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))

 

;)

  • Leaders
Posted
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...

[sIGPIC]e[/sIGPIC]
Posted
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.
Anybody looking for a graduate programmer (Midlands, England)?
Posted

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.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]
Posted
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.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...