Answer the question
In order to leave comments, you need to log in
Can it be written in one line?
public class Tasker :aTasker {
....
protected override void MakeTask() {
var leader =( (ui as UI).leader == null || (ui as UI).b_leader_dead || !(ui as UI).leader.isValid || .... )? null : (ui as UI).leader.Owner; //так работает
//можно сделать в 3 строки, но это приводит к ошибкам в подобном аналогичном использовании - см. коммент ниже
var lui =ui as UI;
var l = lui.leader;
var leader = (l == null || lui.b_leader_dead || !l.isValid)? null : l.Owner;
// можно ли сделать как то так:
var leader => { var lui =ui as UI; var l = lui.leader; return (l == null || lui.b_leader_dead|| !l.isValid) ? null : l.Owner; };
....
}
....
}
Answer the question
In order to leave comments, you need to log in
var leader = new Func<Entity>(() => { var lui =ui as UI; var l = lui.leader; return (l == null || lui.b_leader_dead|| !l.isValid) ? null : l.Owner; })();
can be written like this:
if(ui is UI {leader: { IsValid: true, Owner: var leaderOwner}, b_leader_is_dead: false, } )
{
// делаем что-то с владельцем лидера
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question