我有一个数据库表(SQLite的)检索与猫的字段名称,重量,颜色,地址,纬度,经度和更..... 表名的变数包含一些180行。 现在我想把这些猫放在地图上作为他们经纬度的点。 我已经定义了一个Cat对象,并且想要在运行时读取表并定义180个带有猫名称的变量。 读取数据很简单,但我找不到在C#中用猫的名字定义180个变量的方法。如何创建与数据库中
的数据库信息被读入一个DataTable dtCats与列catName,catLat,catLon(更多...) 后来我做:
nrOfCats = dtCats.Rows.Count;
for (int i = 0; i< nrOfCats; i++)
{
currentCatName = dtCats.Rows[i]["catName"].ToString();
currentCatLat = dtCats.Rows[i]["catLat"].ToString();
currentCatLon = dtCats.Rows[i]["catLon"].ToString();
PointLatLng catLocation = new PointLatLng(Convert.ToDouble(currentCatLat), Convert.ToDouble(currentCatLon));
GmapMarker <the value of currentCatName> = new GMarkerGoogle(catLocation, GMarkerGoogleType.green_pushpin); // this <the value of currentCatName> is the problem
mapOverlayCatMarkers.Markers.Add(<the value of currentCatName>, catLocation);
}
等.... (当然这个“”不是变量名,它应该是currentCatName变量的值)
你为什么要创建180个变量,而不是OS将它们存储在集合中? – 2014-08-28 19:06:13
这种方法从根本上战斗你在工作语言 – grin0048 2014-08-28 19:06:49
边注:请不要加感谢信,署名和“搜索了很多”给你的职位。如果你想展示你的研究成果 - 把你尝试过的代码或包含你找到的问题/文章的链接用一行描述为什么不适合你的案例。 – 2014-08-28 19:16:48