Click here to Skip to main content
15,891,513 members
Home / Discussions / C#
   

C#

 
AnswerRe: Needing help with threads and delegates Pin
Eddy Vluggen18-Oct-12 6:17
professionalEddy Vluggen18-Oct-12 6:17 
GeneralRe: Needing help with threads and delegates Pin
turbosupramk318-Oct-12 6:24
turbosupramk318-Oct-12 6:24 
Questionto send data to an IP address Pin
GzMs18-Oct-12 3:16
GzMs18-Oct-12 3:16 
AnswerRe: to send data to an IP address Pin
Ravi Bhavnani18-Oct-12 3:40
professionalRavi Bhavnani18-Oct-12 3:40 
GeneralRe: to send data to an IP address Pin
GzMs18-Oct-12 4:46
GzMs18-Oct-12 4:46 
GeneralRe: to send data to an IP address Pin
Ravi Bhavnani18-Oct-12 4:57
professionalRavi Bhavnani18-Oct-12 4:57 
AnswerRe: to send data to an IP address Pin
Ingo18-Oct-12 6:06
Ingo18-Oct-12 6:06 
AnswerRe: to send data to an IP address Pin
jschell18-Oct-12 9:39
jschell18-Oct-12 9:39 
QuestionCan save images to a structured text file C#? Pin
Member 245846718-Oct-12 1:27
Member 245846718-Oct-12 1:27 
AnswerRe: Can save images to a structured text file C#? Pin
Eddy Vluggen18-Oct-12 1:39
professionalEddy Vluggen18-Oct-12 1:39 
AnswerRe: Can save images to a structured text file C#? Pin
BobJanova18-Oct-12 5:46
BobJanova18-Oct-12 5:46 
GeneralRe: Can save images to a structured text file C#? Pin
Member 245846721-Nov-12 16:01
Member 245846721-Nov-12 16:01 
Newshow to create send and receive appln Pin
jeny joseph18-Oct-12 0:10
jeny joseph18-Oct-12 0:10 
GeneralRe: how to create send and receive appln Pin
Pete O'Hanlon18-Oct-12 0:41
mvePete O'Hanlon18-Oct-12 0:41 
QuestionVariable declaration. Pin
Sibasisjena17-Oct-12 22:12
professionalSibasisjena17-Oct-12 22:12 
AnswerRe: Variable declaration. Pin
Eddy Vluggen17-Oct-12 22:40
professionalEddy Vluggen17-Oct-12 22:40 
AnswerRe: Variable declaration. Pin
V.17-Oct-12 22:41
professionalV.17-Oct-12 22:41 
GeneralRe: Variable declaration. Pin
Sibasisjena17-Oct-12 22:51
professionalSibasisjena17-Oct-12 22:51 
GeneralRe: Variable declaration. Pin
V.17-Oct-12 22:58
professionalV.17-Oct-12 22:58 
AnswerRe: Variable declaration. Pin
Pete O'Hanlon17-Oct-12 22:49
mvePete O'Hanlon17-Oct-12 22:49 
AnswerRe: Variable declaration. Pin
Shanmuga Hariharan17-Oct-12 22:55
Shanmuga Hariharan17-Oct-12 22:55 
GeneralRe: Variable declaration. Pin
Pete O'Hanlon17-Oct-12 23:22
mvePete O'Hanlon17-Oct-12 23:22 
AnswerRe: Variable declaration. Pin
BobJanova18-Oct-12 1:13
BobJanova18-Oct-12 1:13 
Variables should always be defined in the tightest scope that they are needed for. This is an extension of the principle that says you should have class instance variables not static or global ones, and that you should have function/procedure local variables not instance ones.

So if the variable's only used inside the block, declare it inside. That's true whether it's a try, an if, a while or whatever.

You can even scope sections of code simply to create a localisation region, e.g.

void SomeMethod(){
 {
  int a = 1;
  Console.WriteLine(a); // 1
 }
 {
  string a = "test";
  Console.WriteLine(a); // test
 }
}


That is not generally something that people recommend, though.
GeneralRe: Variable declaration. Pin
Pete O'Hanlon18-Oct-12 1:22
mvePete O'Hanlon18-Oct-12 1:22 
GeneralRe: Variable declaration. Pin
BobJanova18-Oct-12 1:36
BobJanova18-Oct-12 1:36 

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.