【发布时间】:2017-01-23 07:40:46
【问题描述】:
所以我正在使用这个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; }
}
}
【问题讨论】:
标签: c# json linq api console-application