Any language supports this type of syntax?
-
int nThatVeryLongVariableYourMateNamed = 0;
if(nThatVeryLongVariableYourMateNamed != (0,1,2))
{
//Do something
}Instead of having to do like:
int nThatVeryLongVariableYourMateNamed = 0;
if(nThatVeryLongVariableYourMateNamed != 0 &&
nThatVeryLongVariableYourMateNamed != 1 &&
nThatVeryLongVariableYourMateNamed != 2
)
{
//Do something
}-VUNIC
{
int localVLVYMN = thatVeryLongVariableYourMateNamed;
}As a single block, so that your temp-int is limited in scope. Also spitting on the hungarian notation - I would not tough that code with a polearm :thumbsup:
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
{
int localVLVYMN = thatVeryLongVariableYourMateNamed;
}As a single block, so that your temp-int is limited in scope. Also spitting on the hungarian notation - I would not tough that code with a polearm :thumbsup:
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
For extra C#7 goodness:
{
ref int localVLVYMN = ref thatVeryLongVariableYourMateNamed;
...
}Now any changes to your alias will be reflected in the original. :) An added benefit for large
struct
s: you avoid making a copy of the value. Ref return values and ref locals (C# Guide) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
For extra C#7 goodness:
{
ref int localVLVYMN = ref thatVeryLongVariableYourMateNamed;
...
}Now any changes to your alias will be reflected in the original. :) An added benefit for large
struct
s: you avoid making a copy of the value. Ref return values and ref locals (C# Guide) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Richard Deeming wrote:
Now any changes to your alias will be reflected in the original. :)
More ways to obfuscate my code :-D
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
Richard Deeming wrote:
Now any changes to your alias will be reflected in the original. :)
More ways to obfuscate my code :-D
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
More job security. :-D
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
More job security. :-D
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
int nThatVeryLongVariableYourMateNamed = 0;
if(nThatVeryLongVariableYourMateNamed != (0,1,2))
{
//Do something
}Instead of having to do like:
int nThatVeryLongVariableYourMateNamed = 0;
if(nThatVeryLongVariableYourMateNamed != 0 &&
nThatVeryLongVariableYourMateNamed != 1 &&
nThatVeryLongVariableYourMateNamed != 2
)
{
//Do something
}-VUNIC
-
Wasn't the old visual basic capable to use WITH?
www.robotecnik.com[^] - robots, CNC and PLC programming
-
int nThatVeryLongVariableYourMateNamed = 0;
if(nThatVeryLongVariableYourMateNamed != (0,1,2))
{
//Do something
}Instead of having to do like:
int nThatVeryLongVariableYourMateNamed = 0;
if(nThatVeryLongVariableYourMateNamed != 0 &&
nThatVeryLongVariableYourMateNamed != 1 &&
nThatVeryLongVariableYourMateNamed != 2
)
{
//Do something
}-VUNIC
In Python you can use range(). So, for [0,1,2] you would do either;
if nThatVeryLongVariableYourMateNamed not in [0,1,2]:
or
if nThatVeryLongVariableYourMateNamed not in range(3):
or
if nThatVeryLongVariableYourMateNamed not in range(0,3):
or
if nThatVeryLongVariableYourMateNamed not in range(0,3,1):
Dave Find Me On:Web|Youtube|Facebook|Twitter|LinkedIn Folding Stats: Team CodeProject
-
In Python you can use range(). So, for [0,1,2] you would do either;
if nThatVeryLongVariableYourMateNamed not in [0,1,2]:
or
if nThatVeryLongVariableYourMateNamed not in range(3):
or
if nThatVeryLongVariableYourMateNamed not in range(0,3):
or
if nThatVeryLongVariableYourMateNamed not in range(0,3,1):
Dave Find Me On:Web|Youtube|Facebook|Twitter|LinkedIn Folding Stats: Team CodeProject
-
You could do that as an extension method in C# pretty easily. The syntax would be something like ```csharp if (nThatVeryLongVariableYourMateNamed.Excludes(0,1,2)) ```
This space for rent
Copy paste from SOverflow
static class Extensions
{public static bool In(this T item, params T\[\] items) { if (items == null) throw new ArgumentNullException("items"); return items.Contains(item); }
}
class Program
{static void Main() { int myValue = 1; if (myValue.In(1, 2, 3)) // Do Somthing... string ds = "Bob"; if (ds.In("andy", "joel", "matt")) // Do Someting... }
}