由于保护级别,无法将变量传递给c#中的对象

时间:2016-05-01 23:02:17

标签: c# xamarin xamarin.android encapsulation

我有这个代码,并尝试将两个参数传递给LatLng(如果硬编码它工作正常),但由于其保护级别而无法访问 - 在var location = new LatLng ...

我的封装有什么问题?

var a = [{"commentID":"5","name":"name 1","comment":"comment 1","comment_time":"1460652379","blog_unique_id":"19","comment_status":"1"},{"commentID":"6","name":"name 2","comment":"comment 2","comment_time":"1460652387","blog_unique_id":"19","comment_status":"1"},{"commentID":"7","name":"name 3","comment":"comment 3","comment_time":"1460652416","blog_unique_id":"19","comment_status":"1"},{"commentID":"8","name":"name 4","comment":"comment 4","comment_time":"1460652425","blog_unique_id":"19","comment_status":"1"},{"commentID":"9","name":"name 5","comment":"comment 5","comment_time":"1460652433","blog_unique_id":"19","comment_status":"1"}]

var b = {"Comments": []};

for (var prop in a) {
  b.Comments.push(a[prop]);
}

1 个答案:

答案 0 :(得分:1)

Android的LatLng construtor期望一个双倍,你传递一个字符串。这应该给你一个类型转换错误,而不是保护级别错误,但这似乎是基本问题。

string currentLocationLatitude = Intent.GetStringExtra ("currentLocationLatitude");
string currentLocationLongitude = Intent.GetStringExtra ("currentLocationLongitude");

double lat = Double.Parse(currentLocationLatitude);
double lng = Double.Parse(currentLocationLongitude);

var location = new LatLng(lat, lng);