Question: I have following array and getting this result:

```
Array
(
    [0] => stdClass Object
        (
            [UnitIdx] => 10
            [Title] => 순차
            [Description] => 
            [NumSteps] => 9
            [ThumbnailPathName] => Level_1_Unit_thumbnail_Small.png
            [Step_1] => 4
            [Step_2] => 5
            [Step_3] => 6
            [Step_4] => 7
            [Step_5] => 8
            [Step_6] => 9
            [Step_7] => 10
            [Step_8] => 11
            [Step_9] => 12
            [Step_10] => 0
            [Step_11] => 0
            [Step_12] => 0
            [Step_13] => 0
            [Step_14] => 0
            [Step_15] => 0
            [Step_16] => 0
            [Step_17] => 0
            [Step_18] => 0
            [Step_19] => 0
            [Step_20] => 0
        )
)

```

Now I want to find key form value. For example value is `11` so key is `Step_8`.

Any idea how to return key name from value?

Thanks.

Answer: 
### First version

```
static void Caller()
{
    Task<int> test = TestMethod();
    int k = test.Result;
    Console.WriteLine("k: " + k);
}

```

In this version the `async` keyword would be obsolete. This is a *synchronous* method. The executing thread blocks at `test.Result` until the task has finished.

### Second version

```
static async Task Caller()
{
    Task<int> test = TestMethod();
    int i = await test;
    Console.WriteLine("i: " + i);
}

```

This is a (kind of) *asynchronous* version (it's not *really* asynchron, it's just a synchronous method run on a different thread). The difference to the first version is that the compiler builds a state machine for this.  

So the control flow of the executing thread is returned to the caller of this method when `await test` is reached.  

When the task has finished, the execution of this method is resumed at `Console.WriteLine` (or more precisely at the assignment to `i`).

For more information about what the compiler does you can read for example [this](https://learn.microsoft.com/en-us/previous-versions/hh191443(v=vs.140)).

---

The second version is useful if you have a longer running task that you need to execute from an UI. Since the control is returned to the caller while awaiting the task, the UI thread is not blocked and your application stays responsive.
`Task.Result` is equivalent to `Task.Wait` Method which blocks synchronously until the task is complete.

`await` on the other hand waits asynchronously till the task is completed. 

If you can `await` is better.