Click here to Skip to main content
15,914,342 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to store radiobutton status in app.config Pin
Member 1026351910-Nov-13 19:45
Member 1026351910-Nov-13 19:45 
QuestionGetting the value of TreeList in DevExpress Pin
nhanlaptrinh7-Nov-13 23:02
nhanlaptrinh7-Nov-13 23:02 
AnswerRe: Getting the value of TreeList in DevExpress Pin
Eddy Vluggen8-Nov-13 5:01
professionalEddy Vluggen8-Nov-13 5:01 
Questionforeach (TerminalGroup tg in vps) return tg; Pin
Marc W7-Nov-13 22:52
Marc W7-Nov-13 22:52 
AnswerRe: foreach (TerminalGroup tg in vps) return tg; Pin
Pete O'Hanlon7-Nov-13 23:47
mvePete O'Hanlon7-Nov-13 23:47 
GeneralRe: foreach (TerminalGroup tg in vps) return tg; Pin
harold aptroot7-Nov-13 23:54
harold aptroot7-Nov-13 23:54 
GeneralRe: foreach (TerminalGroup tg in vps) return tg; Pin
Marc W8-Nov-13 0:11
Marc W8-Nov-13 0:11 
GeneralRe: foreach (TerminalGroup tg in vps) return tg; Pin
harold aptroot8-Nov-13 0:35
harold aptroot8-Nov-13 0:35 
Depends on what the thing is.
For arrays, there is literally no difference. The assembly code generated by the JIT compiler is exactly the same, at least in my test case.
C#
static int Test2(int[] array)
{
    if (array.Length > 0)
        return array[0];
    throw new Exception();
}

static int Test1(int[] array)
{
    foreach (int i in array)
        return i;
    throw new Exception();
}

ASM
push        rbx 
sub         rsp,20h 
mov         rax,qword ptr [rcx+8] 
test        eax,eax 
jle         0000000000000020 ; goes to throw new Exception()
test        rax,rax 
jbe         0000000000000040 ; unreachable?? code at 40 seems to throw some exception
mov         eax,dword ptr [rcx+10h] ; get array[0]
add         rsp,20h 
pop         rbx 
ret 

For other things, of course you can construct a type such that indexing is slow (always, also at index 0) and enumeration is fast, but usually starting to enumerate means setting up a little state machine (takes some non-zero but usually tiny amount of time) and indexing at index 0 is usually trivial.

TL;DR I would guesstimate that the second way is faster more often than it is slower.
QuestionHow to Create a Deleted Database using LINQ-to-SQL-Classes? Pin
salehne7-Nov-13 18:50
salehne7-Nov-13 18:50 
Questioncombobox in c# Pin
Member 102635197-Nov-13 18:44
Member 102635197-Nov-13 18:44 
AnswerRe: combobox in c# Pin
CodeBlack7-Nov-13 19:58
professionalCodeBlack7-Nov-13 19:58 
Generalinserting radiobutton status dynamically in app.config Pin
Member 102635197-Nov-13 20:33
Member 102635197-Nov-13 20:33 
GeneralRe: combobox in c# Pin
CodeBlack7-Nov-13 21:13
professionalCodeBlack7-Nov-13 21:13 
GeneralRe: combobox in c# Pin
Member 102635197-Nov-13 22:03
Member 102635197-Nov-13 22:03 
GeneralRe: combobox in c# Pin
CodeBlack7-Nov-13 22:07
professionalCodeBlack7-Nov-13 22:07 
GeneralRe: combobox in c# Pin
Member 102635197-Nov-13 22:28
Member 102635197-Nov-13 22:28 
GeneralRe: combobox in c# Pin
CodeBlack7-Nov-13 21:38
professionalCodeBlack7-Nov-13 21:38 
AnswerRe: combobox in c# Pin
Bernhard Hiller7-Nov-13 21:16
Bernhard Hiller7-Nov-13 21:16 
QuestionCannot evaluate expression because a native frame is on top of the call stack Pin
josephdalebert7-Nov-13 3:17
josephdalebert7-Nov-13 3:17 
AnswerRe: Cannot evaluate expression because a native frame is on top of the call stack Pin
Alan Balkany7-Nov-13 4:40
Alan Balkany7-Nov-13 4:40 
GeneralRe: Cannot evaluate expression because a native frame is on top of the call stack Pin
josephdalebert7-Nov-13 5:22
josephdalebert7-Nov-13 5:22 
GeneralRe: Cannot evaluate expression because a native frame is on top of the call stack Pin
Alan Balkany7-Nov-13 5:25
Alan Balkany7-Nov-13 5:25 
GeneralRe: Cannot evaluate expression because a native frame is on top of the call stack Pin
josephdalebert7-Nov-13 5:41
josephdalebert7-Nov-13 5:41 
GeneralRe: Cannot evaluate expression because a native frame is on top of the call stack Pin
Alan Balkany7-Nov-13 5:45
Alan Balkany7-Nov-13 5:45 
GeneralRe: Cannot evaluate expression because a native frame is on top of the call stack Pin
josephdalebert7-Nov-13 6:05
josephdalebert7-Nov-13 6:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.