Kinetic Code Camp - Bring your skills, or lack thereof.. :dumpster_fire:

Edit: Conditionals: Single Line IF-ELSE Statements

Don’t forget the following:

string name  = "Chris"; //Assign a name

if(name == "Chris") Console.WriteLine("Yup"); else Console.WriteLine("Nope");

if(name == "chris") Console.WriteLine("Yup"); else Console.WriteLine("Nope");

if(name == "CHRIS") Console.WriteLine("Yup"); else Console.WriteLine("Nope");

Yields:
Yup
Nope
Nope
4 Likes

I did! Nice catch.

I showed a mixed one, but not a double single line one.

Added.

1 Like

There might be a “better” way, but I’ve done

if(MyString1.ToUpper() == MyString2.ToUpper())

In order to avoid upper/lower/CaMeL case.

3 Likes

There are “better” ways, but almost all of us do that all the time.

It’s when you start dealing with multiple languages and cultures when you have to pay attention.

2 Likes

And I’m a “ToLower()” man.

I’ve threatened to remove the Caps Lock Keys at work.

I could keep them in a jar by my desk, next to the eyeballs of my enemies.

6 Likes

Explain?

You mean like diacritical marks on letters, where résumé (a CV) is different than resume (to start again)?

1 Like

That’s one example, yes.

I can see if I can drag you up an article later that can explain it better than I can.

1 Like
6 Likes

Having only worked on explicitly English-only, USA-only applications … this is surprising to me!

2 Likes

You should have seen the crap we had to do with unicode back in the old days in vb6 lol

3 Likes

Ok I think I might be able to come with a simple how to…At least payment processing

3 Likes

:see_no_evil:

2 Likes

Not to spark a religious war, but I am extremely divided on that one. On one hand, it’s pretty clean looking. On the other hand, I really don’t like seeing (never mind hunting for) semicolons in the middle of lines. One statement per line is a pretty good rule.

Note that I full abuse single line ifs, mostly for exiting methods early. The second there is additional steps in the logic tree, else’s or else if’s, I’m either using braces or some other method.

//example
if (dataViewA.Count == 0 || dataViewB.Count == 0) return true;
if (headerRow["Closed"]) return true;
2 Likes

I’ve got an awful idea… :smiling_imp:

I’ll find a code example, and we’ll all clean it up and post our results.

People can vote and crown a king or queen… :crown:

Or maybe not. That sounds like a lot of work.

Dog Corgi GIF

2 Likes

I don’t even clean my own code up…

1 Like

Not sure if this is brilliant, or it’s one of those take-home interview questions where they’re basically asking you to build a feature for them for free.

1 Like

To be honest, I don’t use this method either. I was primarily trying to show, in C#, case matters. But also, that you can do single line if…then…else statements…

1 Like

As a guy who overuses delegates, I’d use:

string name = "Doug";

Action<string> MatchName = s => Console.WriteLine( name == s? "Yup": "Nope" );

MatchName("Doug"); // Writes "Yup"
MatchName("DOUG"); // Writes "Nope"
MatchName("Dug");  // Writes "Nope"
1 Like

…or even better:

string name = "Doug";

Action<string> MatchName = s => Console.WriteLine( name == s? "Yup": "Nope" );

var NamesToCheck = new List<string>{ "Doug", "DOUG", "doug" };

NamesToCheck.ForEach( MatchName );
1 Like

You’ve got issues.

1 Like