In C# is there a shorthand way to write this:
public static bool IsAllowed(int userID)
{
return (userID == Personnel.JohnDoe || userID == Personnel.JaneDoe ...);
}
Like:
public static bool IsAllowed(int userID)
{
return (userID in Personnel.JohnDoe, Personnel.JaneDoe ...);
}
I know I could also use switch, but there are pro...
What is the answer to this C question:
What's the "condition" so that the following code
snippet prints both HelloWorld !
if "condition"
printf ("Hello");
else
printf("World");
...
I have an if statment with two conditions (seperated by an OR operator), one of the conditions covers +70% of situations and takes far less time to process/execute than the second condition, so in the interests of speed i only want the second condition to be processed if the first condition evaluates to false.
if i order the conditions ...
How do you write the syntax for a While loop?
C#
int i = 0;
while (i != 10)
{
Console.WriteLine(i);
i++;
}
VB.Net
Dim i As Integer = 0
While i <> 10
Console.WriteLine(i)
i += 1
End While
PHP
<?php
while(CONDITION)
{
//Do something here.
}
?>
<?php
//MySQL query stuff here
$result = mysql_query($sql, $link) or ...
I've seen people doing things like this in their HTML:
<!--[if IE]>
<link rel="stylesheet" href="ie.css" type="text/css" />
<![endif]-->
Does this work across all modern browsers and is there a list of browser types that will work with that kind of if statement?
Edit
Thanks Ross. Interesting to find out about gt, lt, gte, & lte.
...
These for-loops are among the first basic examples of formal correctness proofs of algorithms. They have different but equivalent termination conditions:
1 for ( int i = 0; i != N; ++i )
2 for ( int i = 0; i < N; ++i )
The difference becomes clear in the postconditions:
The first one gives the strong guarantee that i == N after...
Hi! I'm trying to do the following in infopath: I have to choose between 2 options (with bullets), and depending on this, if we choose Option1, I need to display a text field to enter more details, but if Option2 is chosen, I don't need this additional field.
I'm not sure about how to enter a Rule to define this :-(
Anyone could help?
T...
I have the problem that an specific step in Ant can only be executed when we have Java 1.5 installed in the build computer. The task definition uses uses a jar file that was compiled using 1.5, so running with a 1.4 virtual machine will throw an IncompatibleClassVersion exception.
I have to find a solution meanwhile to have this task ...
Why does the code below return true only for a = 1?
main(){
int a = 10;
if (true == a)
cout<<"Why am I not getting executed";
}
...
I personally like the 'exclusive or' operator when it makes sense in context of boolean checks because of its conciseness. I much prefer to write
if (boolean1 ^ boolean2)
{
//do it
}
than
if((boolean1 && !boolean2) || (boolean2 && !boolean1))
{
//do it
}
but I often get confused looks (from other experienced java developers, n...
Ruby has a wealth of conditional constructs, including if/unless, while/until etc.
The while block from C
while (condition) {
...
}
can be directly translated to Ruby:
while condition
...
end
However, I can't seem to find a built-in equivalent in Ruby for a C-like do ... while block (in which the block contents are execu...
I've got a table of hardware and a table of incidents. Each hardware has a unique tag, and the incidents are tied to the tag.
How can I select all the hardware which has at least one incident listed as unresolved?
I can't just do a join, because then if one piece of hardware had multiple unresolved issues, it would show up multiple tim...
I am trying to use set.insert (key) as a conditional, where if the key is inserted correctly (meaning that the key does NOT already exsist in the set ) then it should go on and perform some kind of code. For example, something like:
if (set.insert( key ) {
// some kind of code
}
Is this allowed? Because the compiler is throw...
I am new to programming, and am wondering if there is a correct way to order your control structure logic.
It seems more natural to check for the most likely case first, but I have the feeling that some control structures won't work unless they check everything that's false to arrive at something that's true (logical deduction?)
It wou...
Alright, so I have a query that looks like this:
SELECT
`orders`.*,
GROUP_CONCAT(
CONCAT(
`menu_items`.`name`,
' ($',
FORMAT(`menu_items`.`price`,2),
')'
) SEPARATOR '<br>'
) as `items`,
SUM(`menu_items`.`price`) as `additional`,
`children`.`first_name...
I want to check if a variable has a valid year using a regular expression. Reading the bash manual I understand I could use the operator =~
Looking at the example below, I would expect to see "not OK" but I see "OK". What am I doing wrong?
i="test"
if [ $i=~"200[78]" ]
then
echo "OK"
else
echo "not OK"
fi
...
OK, so Sybase (12.5.4) will let me do the following to DROP a table if it already exists:
IF EXISTS (
SELECT 1
FROM sysobjects
WHERE name = 'a_table'
AND type = 'U'
)
DROP TABLE a_table
GO
But if I try to do the same with table creation, I always get warned that the table already exists, because it went ahead and tried...
Hello,
I'm trying to understand a particular Perl code from vcake. Usually I find my way around in Perl but the following statement baffles me. I suspect that this is simply an error but I'm not completely sure. The statement is:
foreach my $seq (keys %$set) {
if( (defined $set->{$seq}) and (my $numReads >= ($coverage)) ) {
...
i am trying to use an ASP conditional here:
if (Request.Cookies("username")) and
(Request.Cookies("password")) <> ""
Then
And i keep getting this error:
Type mismatch: '[string: ""]'
Any ideas what I am getting that?
Thanks,
Ryan
...
Hi there,
I have a Stored Procedure called spGetOrders which accepts a few parameters: @startdate and @enddate. This queries an "Orders" table. One of the columns in the table is called "ClosedDate". This column will hold NULL if an order hasn't been closed or a date value if it has. I'd like to add a @Closed parameter which will ta...