将变量传递给另一个类
问题描述:
我有一个xaml.cs文件,我接收经纬度并将其写入变量。 像这样将变量传递给另一个类
public async void WeatherDisplay()
{
try
{
//var position = await LocationManager.GetPosition();
var geoLocator = new Geolocator();
Geoposition pos = await geoLocator.GetGeopositionAsync();
lat = pos.Coordinate.Point.Position.Latitude;
lon = pos.Coordinate.Point.Position.Longitude;
catch
{
}
}
我需要这个值传递给另一个.cs文件,并将其写入到DB
这里是写DB代码。
public class CreatingBD
{
private string path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");
public void Create()
{
SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path);
conn.CreateTable<DataForWeather>();
conn.Insert(new DataForWeather()
{
lat = WeatherDisplay,
lon = lonParam
});
}
public class DataForWeather
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public double lat { get; set; }
public double lon { get; set; }
public string city { get; set; }
}
}
凡lat
和lon
是这些变量。
感谢您的帮助。
阅读依赖倒置。 – Nkosi
在将这些值传递给另一个类之前,请确保您声明的类具有** public **方法 –
我编辑了我的问题 – Eugene