因此,我使用此API显示当前价格和其他东西,当涉及到以太币硬币。我正在尝试创建一个小型控制台应用程序,用于检查该值是否从我们上次扫描时的值发生变化。如何比较旧数据类型值与新数据类型值
我到目前为止是这样的。而且我知道我正在用当前值扫描当前值,所以显然它永远不会改变。 我试着设置一个变量来保存旧的值,但是没有做任何事情。
如何将第一次扫描与第二次扫描进行比较,以查看浮点值是否已升高或降低?
private static void Ticker()
{
while (true)
{
const string uri = @"https://api.coinmarketcap.com/v1/ticker/ethereum/";
var client = new WebClient();
var content = client.DownloadString(uri);
var results = JsonConvert.DeserializeObject<List<CoinApi>>(content);
float currentAmount = results[0].price_usd;
if (currentAmount < currentAmount)
{
Console.WriteLine("Ammount is lower than the last time.");
}
else if (currentAmount > currentAmount)
{
Console.WriteLine("The amount is higher than the last time.");
}
else if (currentAmount == currentAmount)
{
Console.WriteLine("The amount hasnt changed since the last time we scanned.");
}
}
}
这是类文件。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CryptoTicker.Core
{
class Main
{
}
public class CoinApi
{
public string Id { get; set; }
public string Name { get; set; }
public string Symbol { get; set; }
public float price_usd { get; set; }
}
}
我的方法允许处理多个硬币实例,如果您只需要管理一个价格,那么其他用户发布的更简单的方法可能更合乎需要 – Ben