-
Oct 31st, 2021, 12:33 PM
#1
[RESOLVED] Any difference with parenthesis?
I was translating a vb.net code and since the not and the and the stuff are easy to miss I passed it into a translator just to be sure.
So this ended up with a code with double parenthesis from the translator.
So is there any difference ?
Code:
//me
if (!Uroles.IsAdmin && !Uroles.IsGUser) this.Response.Redirect("~/Default.aspx");
//translator
if ((!Uroles.IsAdmin && !Uroles.IsGUser))
{
this.Response.Redirect("~/Default.aspx");
}
The original was:
If Not URoles.IsAdmin And Not URoles.IsGUserThen Me.Response.Redirect("~/Default.aspx")
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Nov 1st, 2021, 04:31 AM
#2
Re: Any difference with parenthesis?
Both are Valid,
The Parenthesis are required if you have multiple lines after your if statement e.g.
if ((!Uroles.IsAdmin && !Uroles.IsGUser))
{
log.Write("Invalid Login");
this.Response.Redirect("~/Default.aspx");
}
Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you
-
Nov 1st, 2021, 07:25 AM
#3
Re: Any difference with parenthesis?
The double parens feels like overkill to me... Not sure why it did that for you, clearly they were already there. Other than that, it's basically a stylistic choice as to the use of the curly braces. Personally I use them because then it's easier to add additional lines for what ever reason down the road.
-tg
-
Nov 1st, 2021, 07:29 AM
#4
Re: Any difference with parenthesis?
Originally Posted by techgnome
Personally I use them because then it's easier to add additional lines for what ever reason down the road.
Exactly why I do the same thing. It's all about maintainability when you come back to visit later and make changes.
I actually auto-stub out the IF like this...
...Just so it's nice and indented and in the right spot...
-
Nov 1st, 2021, 08:06 AM
#5
Re: Any difference with parenthesis?
Thanks.
I'm a little confused on what some said.
Isn't this valid?
Code:
if (!Uroles.IsAdmin && !Uroles.IsGUser)
{
log.Write("Invalid Login");
this.Response.Redirect("~/Default.aspx");
}
Or I'm missing something?
I think szlamany is answering on C# but is thinking Javascript
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Nov 1st, 2021, 08:12 AM
#6
Re: Any difference with parenthesis?
Originally Posted by sapator
I think szlamany is answering on C# but is thinking Javascript
Yup! Guilty as charged!
-
Nov 1st, 2021, 08:28 AM
#7
Re: Any difference with parenthesis?
Originally Posted by sapator
Thanks.
I'm a little confused on what some said.
Isn't this valid?
Code:
if (!Uroles.IsAdmin && !Uroles.IsGUser)
{
log.Write("Invalid Login");
this.Response.Redirect("~/Default.aspx");
}
Or I'm missing something?
I think szlamany is answering on C# but is thinking Javascript
Yes, it's perfectly valid... that's why I'm a little confused as to why the translator added more parens to it... unless it just blindly did it.
-tg
-
Nov 1st, 2021, 12:22 PM
#8
Re: Any difference with parenthesis?
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Nov 7th, 2021, 03:57 PM
#9
Re: Any difference with parenthesis?
Originally Posted by szlamany
Exactly why I do the same thing. It's all about maintainability when you come back to visit later and make changes.
I actually auto-stub out the IF like this...
...Just so it's nice and indented and in the right spot...
well... c# coding standards put the opening curly bracket on a new line.
-
Nov 8th, 2021, 05:14 AM
#10
Re: Any difference with parenthesis?
Originally Posted by Lord Orwell
well... c# coding standards put the opening curly bracket on a new line.
Sapator figured out I was in the wrong room, lol!
Originally Posted by sapator
I think szlamany is answering on C# but is thinking Javascript
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|