Моя версия будет:
private async void ButtonSingleGetValues_Click(object sender, RoutedEventArgs e)
{
//I wouldn't use the word "single" in an array of ints because single is a floating point number type
//use plurals for collections
//do not need to specify array size with initializer
int[] numbers = new int[] { 1, 5, 10, 15, 20 };
//name your result bool more simply, do not mention single
//name your text box more simply
//windows controls like textbox tend to be named with the textbox word at the end
bool success = int.TryParse(FindIntTextBox.Text, out int findInt);
//personally, I prefer "test bad input, then return if it's bad"
//instead of ending up with nested nested code blocks that run for screens at a time
//it's kinda anathema to the "never use return mid method" crowd though
if (!success)
{
await new MessageDialog("Not a valid integer in the ... box").ShowAsync();
return;
}
//local variables are namedLikeThis, private are typically _namedLikeThis and public are NamedLikeThis
//do not use Array.Find on simple ints etc: you know what you're finding
//array.Find would be used for looking up eg a person by name
//you already know the value to find and just want its index
int foundIndex = Array.IndexOf(numbers, findInt);
//If there is a way to structure a test so that there is
//either a resulting one line operation to perform or a ten line op, i
//tend to place the the shorter code in the if and the longer
//code in the else. This way the condition that applies to
//the else is likely still visible on screen whereas if the if is
//long the else can lose meaning without a scroll. I could
//also have used the "if bad return" here but I do subscribe
//to "avoid return mid method if possible" and we've already started our processing
if(foundIndex == -1)
await new MessageDialog("not a known number").ShowAsync();
else
{
//not sure why you'd bother unless the int parse tolerated eg spaces
FindIntTextBox.Text = findInt.ToString();
FoundIndexTextBox.Text = foundIndex.ToString();
}
}
}
Я бы сделал вызовы asyn c await одной строкой await x.YAsync(z);
вместо того, чтобы объявлять переменную только для задачи. Мы обычно делаем это только тогда, когда нам нужно создать задачу, сделать еще немного работы, а затем ждать задачи