函数定义:
public static void ThoroughCollisionDetection(List<BaseLabel> labels)
{}函数调用:
layCityLabel.LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection;问题:
为什么这里的LabelCollisionDetection.ThoroughCollisionDetection;函数调用没有给参数也能执行

解决方案 »

  1.   

    public event Action<List<BaseLabel>> LabelFilter;有个事件
      

  2.   

    你查看下layCityLabel类中,关于LabelFilter定义就好了
      

  3.   

     在 layCityLabel 这个对象的Class 中或者在其父类中
      

  4.   


    using System.Collections.Generic;namespace SharpMap.Rendering
    {
        /// <summary>
        /// Class defining delegate for label collision detection and static predefined methods
        /// </summary>
        public class LabelCollisionDetection
        {
            #region Delegates        /// <summary>
            /// Delegate method for filtering labels. Useful for performing custom collision detection on labels
            /// </summary>
            /// <param name="labels"></param>
            /// <returns></returns>
            public delegate void LabelFilterMethod(List<BaseLabel> labels);        #endregion        #region Label filter methods        /// <summary>
            /// Simple and fast label collision detection.
            /// </summary>
            /// <param name="labels"></param>
            public static void SimpleCollisionDetection(List<BaseLabel> labels)
            {
                labels.Sort(); // sort labels by intersectiontests of labelbox
                //remove labels that intersect other labels
                for (int i = labels.Count - 1; i > 0; i--)
                    if (labels[i].CompareTo(labels[i - 1]) == 0)
                    {
                        if (labels[i].Priority == labels[i - 1].Priority) continue;                    if (labels[i].Priority > labels[i - 1].Priority)
                            labels.RemoveAt(i - 1);
                        else
                            labels.RemoveAt(i);
                    }
            }        /// <summary>
            /// Thorough label collision detection.
            /// </summary>
            /// <param name="labels"></param>
            public static void ThoroughCollisionDetection(List<BaseLabel> labels)
            {
                labels.Sort(); // sort labels by intersectiontests of labelbox
                //remove labels that intersect other labels
                for (int i = labels.Count - 1; i > 0; i--)
                {
                    if (!labels[i].Show) continue;
                    for (int j = i - 1; j >= 0; j--)
                    {
                        if (!labels[j].Show) continue;
                        if (labels[i].CompareTo(labels[j]) == 0)
                            if (labels[i].Priority >= labels[j].Priority)
                            {
                                labels[j].Show = false;
                                //labels.RemoveAt(j);
                                //i--;
                            }
                            else
                            {
                                labels[i].Show = false;
                                //labels.RemoveAt(i);
                                //i--;
                                break;
                            }
                    }
                }
            }        #endregion
        }
    }
      

  5.   

    看错了,委托
    class LayCityLabel
        {
            public delegate void A(List<int> i);
            public A LabelFilter
            {
                get;
                set;
            }
        }    class Program
        {
            public static void ThoroughCollisionDetection(List<int> labels)
            {
                foreach (int item in labels)
                {
                    Console.WriteLine(item);
                }
            }
            static void Main(string[] args)
            {
                LayCityLabel layCityLabel = new LayCityLabel();
                layCityLabel.LabelFilter = ThoroughCollisionDetection;
                layCityLabel.LabelFilter(new List<int>() { 1, 2, 3, 4 });
                Console.Read();
            }
        }