Click here to Skip to main content
15,886,919 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Thought of the Day Pin
DerekT-P24-Jun-20 6:47
professionalDerekT-P24-Jun-20 6:47 
Questionc# var PinPopular
ZurdoDev23-Jun-20 3:10
professionalZurdoDev23-Jun-20 3:10 
AnswerRe: c# var PinPopular
F-ES Sitecore23-Jun-20 3:20
professionalF-ES Sitecore23-Jun-20 3:20 
GeneralRe: c# var Pin
megaadam23-Jun-20 5:12
professionalmegaadam23-Jun-20 5:12 
AnswerRe: c# var PinPopular
Greg Utas23-Jun-20 3:21
professionalGreg Utas23-Jun-20 3:21 
GeneralRe: c# var Pin
Mircea Neacsu23-Jun-20 9:25
Mircea Neacsu23-Jun-20 9:25 
GeneralRe: c# var Pin
Greg Utas23-Jun-20 9:38
professionalGreg Utas23-Jun-20 9:38 
AnswerRe: c# var Pin
GuyThiebaut23-Jun-20 3:21
professionalGuyThiebaut23-Jun-20 3:21 
The advantage of var is if "http://someapi" was a variable or class instance instead of a string literal and you changed its type, you would not then need to refactor the code elsewhere.

In your example it's just a case of habit probably, however it's obvious from what is on the right that it's a string.

It can sometimes make it harder to debug issues as jumping to the class definition might not always be supported in the IDE you use to debug the var url value with or have to wait for the IDE to resolve the type that the var is.

That's my take on var...
“That which can be asserted without evidence, can be dismissed without evidence.”

― Christopher Hitchens

GeneralRe: c# var Pin
obermd23-Jun-20 4:15
obermd23-Jun-20 4:15 
GeneralRe: c# var Pin
GuyThiebaut23-Jun-20 4:39
professionalGuyThiebaut23-Jun-20 4:39 
GeneralRe: c# var Pin
BillWoodruff24-Jun-20 0:48
professionalBillWoodruff24-Jun-20 0:48 
GeneralRe: c# var Pin
GuyThiebaut24-Jun-20 2:34
professionalGuyThiebaut24-Jun-20 2:34 
AnswerRe: c# var PinPopular
Marc Clifton23-Jun-20 3:21
mvaMarc Clifton23-Jun-20 3:21 
GeneralRe: c# var Pin
ZurdoDev23-Jun-20 3:29
professionalZurdoDev23-Jun-20 3:29 
GeneralRe: c# var PinPopular
OriginalGriff23-Jun-20 3:41
mveOriginalGriff23-Jun-20 3:41 
GeneralRe: c# var Pin
obermd23-Jun-20 4:18
obermd23-Jun-20 4:18 
GeneralRe: c# var Pin
Richard Deeming23-Jun-20 4:51
mveRichard Deeming23-Jun-20 4:51 
GeneralRe: c# var Pin
OriginalGriff23-Jun-20 4:59
mveOriginalGriff23-Jun-20 4:59 
GeneralRe: c# var Pin
Nelek23-Jun-20 5:25
protectorNelek23-Jun-20 5:25 
GeneralRe: c# var Pin
Marc Clifton23-Jun-20 5:25
mvaMarc Clifton23-Jun-20 5:25 
GeneralRe: c# var Pin
BillWoodruff24-Jun-20 0:52
professionalBillWoodruff24-Jun-20 0:52 
GeneralRe: c# var Pin
pkfox23-Jun-20 20:46
professionalpkfox23-Jun-20 20:46 
GeneralRe: c# var Pin
Fabio Franco24-Jun-20 12:32
professionalFabio Franco24-Jun-20 12:32 
GeneralRe: c# var Pin
David On Life24-Jun-20 14:03
David On Life24-Jun-20 14:03 
GeneralRe: c# var Pin
dandy7223-Jun-20 7:16
dandy7223-Jun-20 7:16 

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.