C#中的新手。
尝试使用下面的代码来检查S3中是否存在某个bucket。
using System;
using Amazon.S3;
using Amazon.S3.Util;
namespace CRO
{
internal class Program
{
static void Main(string[] args)
{
Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", "123");
Environment.SetEnvironmentVariable("AWS_SECRET_ACCESS_KEY", "456");
Environment.SetEnvironmentVariable("AWS_REGION", "ap-southeast-2");
Console.WriteLine(DoesBucketExist("randombucket").GetType());
Console.WriteLine("Done");
}
public static async Task<bool> DoesBucketExist(string bucketName)
{
using (var s3Client = new AmazonS3Client(Environment.GetEnvironmentVariable("AWS_ACCESS_KEY_ID"), Environment.GetEnvironmentVariable("AWS_SECRET_ACCESS_KEY")))
{
DateTime currentDateTime = DateTime.Now;
Console.WriteLine("Current date and time: " + currentDateTime);
return await AmazonS3Util.DoesS3BucketExistV2Async(s3Client, bucketName);
}
}
}
}
我希望返回一个布尔值(true或false)。
但当我检查下面的数据类型时,我得到的不是“布尔值”。
System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1+AsyncStateMachineBox
1[System.Boolean,CRO.Program+d_1]
对于C#世界来说是非常新鲜的。只是想知道我做错了什么。
尝试使用.net核心(如果有帮助的话)。