我从预先编写的项目开发应用程序,而构建解决方案时我得到错误:
第9行第45页;预期
VS IDE为“=>”添加红色下划线第9行
我正在使用visual studio 2008,我不明白哪里有错。
这是我的代码:
using System;
using System.Net;
using Newtonsoft.Json.Linq;
namespace Main.Tools
{
internal static class Blockr
{
private static string BlockrAddress => "http://btc.blockr.io/api/v1/";
internal static double GetPrice()
{
var request = BlockrAddress + "coin/info/";
var client = new WebClient();
var result = client.DownloadString(request);
var json = JObject.Parse(result);
var status = json["status"];
if ((status != null && status.ToString() == "error"))
{
throw new Exception(json.ToString());
}
return json["data"]["markets"]["coinbase"].Value<double>("value");
}
internal static double GetBalanceBtc(string address)
{
var request = BlockrAddress + "address/balance/" + address;
var client = new WebClient();
var result = client.DownloadString(request);
var json = JObject.Parse(result);
var status = json["status"];
if ((status != null && status.ToString() == "error"))
{
throw new Exception(json.ToString());
}
return json["data"].Value<double>("balance");
}
}
}
答案 0 :(得分:5)
第9行你有
private static string BlockrAddress => "http://btc.blockr.io/api/v1/";
此类属性定义是c#6功能,在vs 2008中不受支持。将其更改为
private static string BlockrAddress {
get { return "http://btc.blockr.io/api/v1/"; }
}
答案 1 :(得分:4)
这是C#6语法(expression bodied member),仅在Visual Studio 2015之后可用:
private static string BlockrAddress => "http://btc.blockr.io/api/v1/";
将其更改为:
private static string BlockrAddress get { return "http://btc.blockr.io/api/v1/" }; //property
或
private static readonly string BlockrAddress = "http://btc.blockr.io/api/v1/"; //field
它应该解决问题
答案 2 :(得分:3)
只需添加private static string BlockrAddress = "http://btc.blockr.io/api/v1/";
代替private static string BlockrAddress => "http://btc.blockr.io/api/v1/";