0

私はこのエラーメッセージを持っています:

統合参照比較の可能性。値の比較を取得するには、左側を文字列型にキャストします

問題 :
((Pushpin)p).Tag == "locationPushpin"));

============================

double Dlat = Convert.ToDouble(g_strLat);            
double Dlon = Convert.ToDouble(g_strLon);

 this.map1.Center = new GeoCoordinate(Dlat, Dlon);           

  if (this.map1.Children.Count != 0)
     {
        var pushpin = map1.Children.FirstOrDefault(p => (p.GetType() == typeof(Pushpin) && ((Pushpin)p).Tag == "locationPushpin"));

         if (押しピン != null)
          {
              this.map1.Children.Remove(押しピン);
          }
      }

     画鋲の場所Pushpin = new Pushpin();

     //---画鋲の位置を設定する---

      locationPushpin.Tag = "locationPushpin";
      locationPushpin.Location = new GeoCoordinate(Dlat, Dlon);

     locationPushpin.Content = new Ellipse()
     {
        Fill = new SolidColorBrush(Colors.Orange),
        //不透明度 = .8,
        高さ = 40、
        幅 = 30
      };

      locationPushpin.Width = 60;
      locationPushpin.Height = 100;

      this.map1.Center = new GeoCoordinate(Dlat, Dlon);
      this.map1.Children.Add(locationPushpin);
      this.map1.ZoomLevel = 13;  

助けていただければ幸いです。ありがとう

4

1 に答える 1

1

まず、クエリはタイプの正確なオブジェクトのみを検索しますPushpin。これはよりクリーンです:

var pushpin = map1.Children.OfType<Pushpin>()
                           .FirstOrDefault(p => p.Tag == "locationPushpin");

次の問題はそれTagがタイプであるということですobject。だからあなたは本当に欲しい:

var pushpin = map1.Children.OfType<Pushpin>()
                           .FirstOrDefault(p => "locationPushpin".Equals(p.Tag));

それ以外の場合は、値と文字列の間で参照比較を行います。したがって、同じであるが別個のTag文字列を持つことができ、画鋲は見つかりません。

于 2012-07-03T14:24:53.033 に答える