There is a code:

Match match = regex.Match(responseFromServer); if (match.Success) { var input = responseFromServer; var split = input.Split(':'); var final = split[3]; ProcessStartInfo mcStartInfo = new Shitocode; Process.Start(mcStartInfo); this.Close(); } else if (responseFromServer == " Bad Login") { MessageBox.Show("Uncorrect login/password!"); } else if (responseFromServer == " Old version") { MessageBox.Show("Launcher is old!"); } 

Why are the last 2 operators not called? :)

I tried this:

 if (match.Success) { var input = responseFromServer; var split = input.Split(':'); var final = split[3]; ProcessStartInfo mcStartInfo = new Shitocode; Process.Start(mcStartInfo); this.Close(); } else if (responseFromServer.Equals("Bad Login")) { MessageBox.Show("Uncorrect login/password!"); } else if (responseFromServer.Equals("Old Version")) { MessageBox.Show("Launcher is old!"); } 

Nothing happens in response

  • one
    What are the last two operators? - alexlz
  • Sorry, but for a var, at the birth of a hand, it is necessary to tear it off, but here it’s not the objects of the devil understand what kind of nesting, but primitive types. Why do I need to declare unused variables? If there is a desire to compare strings by value, then use equals - responseFromServer.Equals ("Bad Login"); check that the server response is exactly what is expected. - Raskilas
  • And what will happen if match.Success = false, and responceFromServer! = "Bad Login" || "Old version" - Mirdin
  • else if - is not called at all. var can not be inside if? If match.Succes = false 2 will be executed next, and responceFromServer! = "Bad Login" || "Old version" where "Bad Login" is the wrong password, and "Old version" is the old version of the program. So the option with OR is not suitable - Artez
  • Let's say a little bit easier - how do you work out an incorrect responceFromServer, if it is not bad_login and not old_version. Yes, var is possible inside if, just in this case it is a rather “dirty” code. - Mirdin

2 answers 2

And are not called apparently because the conditions are not met? You walk in debug look ...

P.S.

Comrades @Mirdin , @rasmisha if you are really interested in the discussion about the use of var , then let's take a separate question, it has nothing to do with the current topic.

  • @Chad, the limit of comments has ended, so I am writing in response. var is for the application "here / now", when it is not particularly important what type, the main data. But going beyond a few lines, it is able to specifically confuse your code, especially if there are several var, and cause errors. Actually it is not necessary to use JStil in a language with strict typification. - Mirdin 2:53
  • @Mirdin, Taki applied to the question of the string - how are they not "here and now"? But in general, this question about var is a matter of habit — for me, for example, var is more convenient than a direct type indication, since - climbs more on eran, less clutter, stimulates to understand what initialization returns rather than waiting for a certain reaction, etc. Resharpyr theses are close: habrahabr.ru/post/39231 - Chad
  • @ Chad, of course it's a matter of habit, but using var is very easy to make a puzzle out of code. A simple example based on the above code var input = responseFromServer; var final = GetFinal (input); // ... some code if (input == final) {// ... some code} And if these pieces are located in different files (partial class for example) - Mirdin
  • Well, this is not possible the same kind of (partial) - a different scope? - Chad
  • partial - one class, divided into several files, from where there is a different scope. - Mirdin

@ Chad ,

Do not confuse scope with nimspace ...

void test () {if (true) {var x = y; }}

How can x crawl to another file using a partial? Moreover how can x creep out for if?

um ... construction of type partial class A {var a; } will not work in the compiler ...

I never, never wrote, checked, didn’t let it go, then another example:

one file:

 partial class A { int foo1 () { return 1; } } 

second file:

 partial class A ``{ int foo2 () { var a = foo1(); if(a==1) { return 1; } } } 

Refactoring was carried out - to find out what is now stored in a (a == 1 - now an error), you will have to climb at least two files.

  • H'm ... and what changes from what will be int a = foo1 ()? besides, if (a == 1) and so it is clear that it is a la int ... but to make a high-quality refactor you will still have to go to foo1 () - Chad
  • If there is an int a, then the error will be exactly on this line, var a - the error will be on the line (a == 1), in a real program everything can be much less obvious, the lines are spaced apart by more than one screen, and somehow class, interface, etc. therefore, until a certain point, everything is good, and then shamanism ... And if there are many such variables ... it is better that the person who will accompany the code does not know your address, even if he is white and fluffy phlegmatic. - Mirdin