It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
try
{
for (int i = 0; i <10; i++)
{
DoStuff();
if (i>3 && 1== i% 2)
{
throw new Exception();
}
}
}
catch (Exception ex)
{
DoOtherStuff();
}
DOSTUFF() is called 0 times because C# method names are case-sensitive.
If you really meant DoStuff(), then assuming it is not an unimplemented partial method and the method itself is not marked with a conditional attribute specifying an undefined symbol, then it will be called 6 times as in #MikeCito's answer.
6 times. When i hits 5 the remainder will be 1 and it will be greater than 3.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
lock("data"){
if(_requestList.Count>1 && _requestList[1]==null){
Debug.Log("why0");
}
_requestList.RemoveAt(0);
if(_requestList.Count > 0 && _requestList[0] == null){
Debug.Log("why1");
}
doSomething ();
}
_requestList is a List of string
Sometimes it logs "why0", sometimes "why1", and sometimes both, and sometimes nothing.
The elements added is never null.
So why?
First of all you need to use a
private readonly object lockObject = new object();
lock(lockObject)
{
}
You also need to put a lock(lockObject) around anywhere where you are adding to the list.
Hope that helps in some regard.
You could also look into a ConcurrentBag if you don't want to worry about threading.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How can I do the following in C# :
var re = /^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$/;
re.test('2013/03/05 15:22:00'); // returns true
You can use the Regex.IsMatch instead (docs).
Regex.IsMatch("2013/03/05 15:22:00", #"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$"); // true if match
The below code should get you where you want to be.
Regex rx = new Regex(#"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$");
String test = "2013/03/05 15:22:00";
if (rx.IsMatch(test))
{
//Test String matches
}
else
{
//Test String does not match
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
i used this code:
List<string> lists=new List<string>("apple","orange","banana","apple","mang0","orange");
string names;
names=lists.Distinct()
is that correct?
No, the variable names has to be a collection. The Distinct method returns an enumerator, so you probably want to enumerate the result and realise it as a list:
List<string> names = lists.Distinct().ToList();
You can sort the list, then check two and two:
list.Sort();
Int32 index = 0;
while (index < list.Count - 1)
{
if (list[index] == list[index + 1])
list.RemoveAt(index);
else
index++;
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have if else condition in one function in oracle
i need to convert that into c# code please help.
IF INSTR( pString, pSeparator, -1, 1) != ( LENGTH( RTRIM( pString )) - LENGTH( pSeparator ) + 1 )
THEN
-- There isn't one at the end so add it
l_Return := pString || pSeparator;
--DBMS_OUTPUT.PUT_LINE('Did not find seperator - ADDING');
In this case you can use string.EndsWith() instead, that's exactly what you are trying to check:
if(!pString.EndsWith(pSeparator))
{
//There isn't one at the end so add it
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have an IF / ELSE statement, although I would like to know how to tell the "else" part to do nothing if it is true. e.g.:
if(x == x)
//run calc.exe
else
//DoNothing
Or I am write in saying that if I just remove the else statement, it will continue anyway if the if condition is not matched?
just omit the else
if(condition)
{
do_something();
}
//go on with your program
Yes. An non existant else statement is the same as an empty one.
This is common to all C-like languages.
If there's nothing to do then just omit the else:
if (some condition)
{
do stuff
}
continue is used in loops to short-circuit the rest of the this iteration of the loop and break is used to terminate the loop early.
If you don't put an else part and the if condition is not met the program will continue executing its flow:
if (SomeCondition)
{
// Do something if the condition is not met
}
// continue executing