Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Important Ingame API Issues

Discussion in 'Programming (In-game)' started by rexxar, Oct 10, 2017.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Malware Master Engineer

    Messages:
    9,861
  2. Sarithule Trainee Engineer

    Messages:
    55
    I would like to use the ability to initiate a variable while making an "if" check like this:

    Code:
    if(block is IMyMotorSator rotor){
    	Echo(rotor.Angle.ToString());
    }
    The compiler does not seem to recognize this syntax. I know that I can add an extra statement like this:

    Code:
    if(block is IMyMotorSator){
    	var rotor = (IMyMotorSator)block;
    	Echo(rotor.Angle.ToString());
    }
    but the first way would save me so many characters.
     
  3. Malware Master Engineer

    Messages:
    9,861
    Believe me, I want this too, but that would mean adding support for a new C# version. That's a lot of work securing all the new C# constructs for rather little gain.

    BTW the recommended way is:
    Code:
    var rotor = block as IMyRotorStator;
    if (rotor != null)
    {
    	//... 
    } 
    
    One less type check and a little shorter code.
     
  4. Sarithule Trainee Engineer

    Messages:
    55
    Very nice, Thanks for the tip :)
     
Thread Status:
This last post in this thread was made more than 31 days old.