将变量传递给另一个类

时间:2016-12-25 12:59:21

标签: c# uwp

我有一个xaml.cs文件,我收到lat和lon并将其写入变量。 喜欢这个

     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; }
        }

    }

latlon是那些变量。

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

方法可以参数。创建一个lat和long作为参数。

public void Create(double latitude, double longitude)
{
    // code removed for brevity
   double lon = longitude;
   double lat = latitude;
}
相关问题