Click here to Skip to main content
15,884,986 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: invert if : visual studio code helper Pin
englebart23-Aug-20 8:01
professionalenglebart23-Aug-20 8:01 
GeneralRe: invert if : visual studio code helper Pin
Mircea Neacsu23-Aug-20 9:03
Mircea Neacsu23-Aug-20 9:03 
GeneralRe: invert if : visual studio code helper Pin
Maximilien4-Aug-20 5:52
Maximilien4-Aug-20 5:52 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 6:04
mvaraddevus4-Aug-20 6:04 
GeneralRe: invert if : visual studio code helper Pin
Nelek4-Aug-20 8:18
protectorNelek4-Aug-20 8:18 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 8:39
mvaraddevus4-Aug-20 8:39 
GeneralRe: invert if : visual studio code helper Pin
Jon McKee4-Aug-20 10:44
professionalJon McKee4-Aug-20 10:44 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 11:40
mvaraddevus4-Aug-20 11:40 
Jon McKee wrote:
I'm curious if this error still pops up if you write more code below the if statement.

That's a very good question.

Here's the updated code that contains more code now. Note: this is simple code that is going in a book.
C#
static void Main(string[] args)
        {
            if (args.Length < 1){
                Console.WriteLine("Please provide 1 argument to indicate the command you want to run.\nUsage: getInfo <command-name>");
                return;
            }

            switch (args[0].ToLower()){
                case "os":{
                    Console.WriteLine($"OS : {Environment.OSVersion}");
                    break;
                }
                case "pwd":{
                    Console.WriteLine($"The current directory is: {Environment.CurrentDirectory}");
                    break;
                }
                case "cl":{
                    Console.WriteLine($"Command line was: {Environment.CommandLine}");
                    break;
                }
                case "sysdir":{
                    Console.WriteLine($"System dir: {Environment.SystemDirectory}");
                    break;
                }
                case "mname":{
                    Console.WriteLine($"Machine name: {Environment.MachineName}");
                    break;
                }
            }
        }


Here's a snapshot of the invert if[^] that still shows up in VSC as a hint.

Here's the code you get if you invert now:

C#
static void Main(string[] args)
        {
            if (args.Length >= 1)
            {
                switch (args[0].ToLower())
                {
                    case "os":
                        {
                            Console.WriteLine($"OS : {Environment.OSVersion}");
                            break;
                        }
                    case "pwd":
                        {
                            Console.WriteLine($"The current directory is: {Environment.CurrentDirectory}");
                            break;
                        }
                    case "cl":
                        {
                            Console.WriteLine($"Command line was: {Environment.CommandLine}");
                            break;
                        }
                    case "sysdir":
                        {
                            Console.WriteLine($"System dir: {Environment.SystemDirectory}");
                            break;
                        }
                    case "mname":
                        {
                            Console.WriteLine($"Machine name: {Environment.MachineName}");
                            break;
                        }
                }
            }
            else
            {
                Console.WriteLine("Please provide 1 argument to indicate the command you want to run.\nUsage: getInfo <command-name>");
                return;
            }
        }

GeneralRe: invert if : visual studio code helper Pin
Jon McKee4-Aug-20 12:11
professionalJon McKee4-Aug-20 12:11 
GeneralRe: invert if : visual studio code helper Pin
raddevus4-Aug-20 16:43
mvaraddevus4-Aug-20 16:43 
GeneralRe: invert if : visual studio code helper Pin
Richard Deeming4-Aug-20 23:41
mveRichard Deeming4-Aug-20 23:41 
GeneralRe: invert if : visual studio code helper Pin
raddevus5-Aug-20 2:14
mvaraddevus5-Aug-20 2:14 
GeneralRe: invert if : visual studio code helper Pin
Jon McKee12-Aug-20 11:14
professionalJon McKee12-Aug-20 11:14 
GeneralRe: invert if : visual studio code helper Pin
Richard Deeming12-Aug-20 22:18
mveRichard Deeming12-Aug-20 22:18 
GeneralRe: invert if : visual studio code helper Pin
Bernhard Hiller4-Aug-20 20:31
Bernhard Hiller4-Aug-20 20:31 
JokeRe: invert if : visual studio code helper Pin
Nelek4-Aug-20 21:44
protectorNelek4-Aug-20 21:44 
GeneralRe: invert if : visual studio code helper Pin
raddevus5-Aug-20 2:09
mvaraddevus5-Aug-20 2:09 
GeneralRe: invert if : visual studio code helper Pin
obermd5-Aug-20 4:07
obermd5-Aug-20 4:07 
GeneralRe: invert if : visual studio code helper Pin
raddevus5-Aug-20 4:23
mvaraddevus5-Aug-20 4:23 
GeneralRe: invert if : visual studio code helper Pin
Greg Utas5-Aug-20 4:22
professionalGreg Utas5-Aug-20 4:22 
GeneralRe: invert if : visual studio code helper Pin
raddevus5-Aug-20 4:31
mvaraddevus5-Aug-20 4:31 
GeneralRe: invert if : visual studio code helper Pin
OriginalGriff5-Aug-20 5:24
mveOriginalGriff5-Aug-20 5:24 
GeneralRe: invert if : visual studio code helper Pin
raddevus5-Aug-20 8:15
mvaraddevus5-Aug-20 8:15 
GeneralRe: invert if : visual studio code helper Pin
Nelek5-Aug-20 8:51
protectorNelek5-Aug-20 8:51 
GeneralRe: invert if : visual studio code helper Pin
Jon McKee12-Aug-20 11:23
professionalJon McKee12-Aug-20 11:23 

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.