Click here to Skip to main content
15,887,267 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: VS Go BOOM! Pin
Lutosław27-Dec-13 1:16
Lutosław27-Dec-13 1:16 
GeneralDetect user in group only once Pin
SortaCore15-Nov-13 0:15
SortaCore15-Nov-13 0:15 
GeneralRe: Detect user in group only once Pin
Lutosław15-Nov-13 0:31
Lutosław15-Nov-13 0:31 
GeneralRe: Detect user in group only once Pin
SortaCore15-Nov-13 0:32
SortaCore15-Nov-13 0:32 
GeneralRe: Detect user in group only once Pin
Lutosław15-Nov-13 0:43
Lutosław15-Nov-13 0:43 
GeneralRe: Detect user in group only once Pin
SortaCore15-Nov-13 0:53
SortaCore15-Nov-13 0:53 
GeneralRe: Detect user in group only once Pin
PIEBALDconsult15-Nov-13 2:57
mvePIEBALDconsult15-Nov-13 2:57 
GeneralRe: Detect user in group only once Pin
Marc Clifton17-Nov-13 4:38
mvaMarc Clifton17-Nov-13 4:38 
SortaCore wrote:
testUser = Array.IndexOf(new string[] { "mrock", "kasante" }, Environment.UserName.ToLower()) != -1;


If you want to get a little tighter about it:

testUser = Array.Exists(new [] { "a", "b" }, t => t=="a");


First of all, you don't need string[] because the compiler can infer the array type.

Second, using "Exists" makes it clearer to the reader what you're doing, especially since you're not interested in the index, you just want to know of the value exists.

Lastly, the use of the predicate t => t == 'a' means you could do some fancier things if you wanted later on -- it's a more general purpose solution. (Where 'a' would actually be in your case Environment.UserName.ToLower()

Marc

GeneralWhat is an Object Pin
michaelbarb14-Nov-13 8:44
michaelbarb14-Nov-13 8:44 
GeneralRe: What is an Object Pin
DaveAuld14-Nov-13 9:00
professionalDaveAuld14-Nov-13 9:00 
GeneralRe: What is an Object Pin
michaelbarb14-Nov-13 9:16
michaelbarb14-Nov-13 9:16 
GeneralRe: What is an Object Pin
Joan M14-Nov-13 9:10
professionalJoan M14-Nov-13 9:10 
GeneralRe: What is an Object Pin
Richard Deeming14-Nov-13 9:17
mveRichard Deeming14-Nov-13 9:17 
GeneralRe: What is an Object Pin
Freak3014-Nov-13 22:02
Freak3014-Nov-13 22:02 
GeneralRe: What is an Object Pin
Pualee14-Nov-13 11:02
Pualee14-Nov-13 11:02 
GeneralRe: What is an Object Pin
michaelbarb14-Nov-13 12:57
michaelbarb14-Nov-13 12:57 
GeneralRe: What is an Object Pin
_Maxxx_14-Nov-13 14:03
professional_Maxxx_14-Nov-13 14:03 
GeneralRe: What is an Object Pin
michaelbarb14-Nov-13 14:24
michaelbarb14-Nov-13 14:24 
GeneralRe: What is an Object Pin
Ron Beyer14-Nov-13 15:39
professionalRon Beyer14-Nov-13 15:39 
GeneralRe: What is an Object Pin
_Maxxx_14-Nov-13 16:38
professional_Maxxx_14-Nov-13 16:38 
GeneralRe: What is an Object Pin
PIEBALDconsult15-Nov-13 7:50
mvePIEBALDconsult15-Nov-13 7:50 
GeneralRe: What is an Object Pin
Member 1008817116-Nov-13 11:12
Member 1008817116-Nov-13 11:12 
GeneralRe: What is an Object Pin
michaelbarb16-Nov-13 14:25
michaelbarb16-Nov-13 14:25 
GeneralRe: What is an Object Pin
Member 1008817116-Nov-13 14:38
Member 1008817116-Nov-13 14:38 
GeneralRe: What is an Object Pin
michaelbarb16-Nov-13 15:32
michaelbarb16-Nov-13 15:32 

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.