本文整理汇总了C#中Animal.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Animal.ToString方法的具体用法?C# Animal.ToString怎么用?C# Animal.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Animal
的用法示例。
在下文中一共展示了Animal.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPictureAsync
public async static Task<String> GetPictureAsync(Animal animal)
{
try
{
Xamarin.Insights.Track("GetPicture", new Dictionary<string, string>
{
{"animal", animal.ToString()}
});
if(animal == Animal.Random)
{
var next = random.Next(0, 100);
if(next < 35)
animal = Animal.Cat;
else if(next < 70)
animal = Animal.Dog;
else
animal = Animal.Otter;
}
var url = string.Empty;
switch (animal)
{
case Animal.Cat:
url = CatUrl;
break;
case Animal.Dog:
url = DogUrl;
break;
default:
url = OtterUrl;
break;
}
var client = new HttpClient(new ModernHttpClient.NativeMessageHandler());
if (client.DefaultRequestHeaders.CacheControl == null)
client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue();
client.DefaultRequestHeaders.CacheControl.NoCache = true;
client.DefaultRequestHeaders.IfModifiedSince = DateTime.UtcNow;
client.DefaultRequestHeaders.CacheControl.NoStore = true;
client.Timeout = new TimeSpan(0, 0, 10);
var imageUrl = await client.GetStringAsync(url);
if (!string.IsNullOrWhiteSpace(imageUrl) && imageUrl.EndsWith("\n"))
imageUrl = imageUrl.TrimEnd('\n');
return imageUrl;
}
catch (Exception ex)
{
return string.Empty;
}
}
示例2: ShowZooAnimal
// Contravariance means only one method is needed to show all
// zoo animals.
static void ShowZooAnimal(Animal a)
{
Console.WriteLine("\n" + a.ToString());
}