linux-packaging-mono/mcs/tests/test-async-03.cs

61 lines
801 B
C#
Raw Normal View History

using System.Runtime.CompilerServices;
using System.Threading.Tasks;
static class S
{
public static A GetAwaiter (this int i)
{
return new A ();
}
}
class A : INotifyCompletion
{
bool IsCompleted {
get {
return true;
}
}
void INotifyCompletion.OnCompleted (System.Action a)
{
}
int GetResult ()
{
return 3;
}
static async Task<int> Test1 ()
{
await checked (1);
return await checked (2);
}
static async Task<int> Test2 ()
{
await checked (1);
return 4;
}
static async Task Test3 ()
{
await checked (1);
}
public static int Main ()
{
var r = Test1 ();
System.Console.WriteLine (r.Result);
if (r.Result != 3)
return 1;
r = Test2 ();
System.Console.WriteLine (r.Result);
if (r.Result != 4)
return 2;
Test3();
return 0;
}
}