我使用以下剃刀代码生成一些javascript以在Google地图上生成标记.
@foreach(Point point in Model.Points.Take(3))
{
String longitude = point.Longitude.ToString(CultureInfo.InvariantCulture);
String latitude = point.Latitude.ToString(CultureInfo.InvariantCulture);
<text>
var location = new google.maps.LatLng(@(longitude), @(latitude));
bounds.extend(location);
var marker = new google.maps.Marker({
position: location,
map: map
});
</text>
}
Run Code Online (Sandbox Code Playgroud)
在开发中,这正确地变为:
var location = new google.maps.LatLng(52.2124273, 5.9545532);
bounds.extend(location);
var marker = new google.maps.Marker({
position: location,
map: map
});
Run Code Online (Sandbox Code Playgroud)
但是,在我们的生产服务器上,它变为:
var location = new google.maps.LatLng(522124273000, 59545532000);
bounds.extend(location);
var marker = new google.maps.Marker({
position: location,
map: map
});
Run Code Online (Sandbox Code Playgroud)
这只是一个灰色的谷歌地图.是什么导致了这种奇怪的ToString
行为?
编辑
Point类是一个自定义类,而不是来自库.以下是相关部分:
public class Point
{
private …
Run Code Online (Sandbox Code Playgroud) 要使用Linq订购列表,我们必须OrderBy
首先调用ThenBy
对下级排序的结果.
我现在处于一种情况,我不知道顶级订购.我有一份应该有条件地应用的订单清单.
像这样:
var list = new List<Tuple<int, string, DateTime>>();
list.Add(new Tuple<int, string, DateTime>(1, "B", new DateTime(2020, 1, 1)));
list.Add(new Tuple<int, string, DateTime>(2, "A", new DateTime(2000, 1, 1)));
list.Add(new Tuple<int, string, DateTime>(3, "C", new DateTime(1900, 1, 1)));
var orderedList = list;
if (sortByString)
{
orderdedList = orderedList.ThenBy(listItem => listItem.Item2);
}
if (sortByDateTime)
{
orderedList = orderedList.ThenBy(listItem => listItem.Item3);
}
orderList = orderedList.ThenBy(listItem => listItem.Item1);
Run Code Online (Sandbox Code Playgroud)
因此,列表将始终按Item1排序,并有条件地按Item2和/或Item3排序.
如何在C#中实现这一目标?没有Linq的解决方案也是受欢迎的.
请参阅此示例:https://github.com/mono/gtk-sharp/blob/master/sample/AsyncSample.cs
它使用async/await来表示UI事件.在等待工作之后,它会检查它是否与UI线程同步(是正确的术语吗?).在我个人的实验中它从来没有,这个例子总是会打印"Not in main thread".
这是正确的行为吗?等待工作后我们应该如何更新UI?
c# ×2
asp.net-mvc ×1
async-await ×1
google-maps ×1
gtk# ×1
javascript ×1
linq ×1
mono ×1
razor ×1
sorting ×1