A类 调用 B类

来源:互联网 发布:jsp订餐系统源码 编辑:程序博客网 时间:2024/05/29 17:24

A类 调用 B类,
1.创建 B类时, A类所需的变量在 B类中为全局变量,且要引入构造函数的参数中。
如在 B类—ProfileGraph 中:
       private IMap _pMap;
       private string _layerName;
       private IPolyline pPolyLine;

       public int DevCount
       {
           get { return _devCount; }
           set { _devCount = value; }
       }

       public ProfileGraph(IMap pMap,stringlayername) //这时是 A类要引用的
       {
           this._pMap=pMap;
           this._layerName = layername;
       }
在 A类中调用时,如:
       //------------全局变量中加上这个!!---------------------------
       private ProfileGraph proFileGraph;
        //初始化时一定要带上参数,并与 B类中函数参数形式对应上
       proFileGraph = new ProfileGraph(XXX.Map,LName);
然后就可以调用 B类中的函数了。