C#.NET描述arcobjects中的介面查詢(QI)技術

來源:互聯網
上載者:User
        在AO或者是AE的二次開發中,介面查詢(QI)技術被認為是最基本,同時也是最重要的技術之一,幾乎每一個GIS系統,甚至是一個小小的GIS功能模組,都不可能不用到介面查詢技術。通俗地說,QI就是類中的顯式強制轉換,請看下面例子。/*
 * Created by SharpDevelop.
 * User: noo
 * Date: 2009-8-18
 * Time: 15:46
 * 
 * 介面查詢(QI)
 */

using System ;
interface IApple//蘋果介面
{
    string spice//香屬性
    {
        get;
        set;
    }
    void circle();//圓方法
}
interface IBanana//香蕉介面
{
    string sweet//甜屬性
    {
        get;
        set;
    }
    void column();//柱方法
}
class Fruit:IApple,IBanana//水果類
{
    private string str1;
    string IApple.spice//注意這裡的寫法
    {
        get{return str1;}
        set{str1=value;}
    }
    void IApple.circle()//同上
    {
        Console.WriteLine ("蘋果介面的成員函數");
    }
    
    private string str2;
    string IBanana.sweet
    {
        get{return str2;}
        set{str2=value;}
    }
    void IBanana.column()
    {
        Console.WriteLine ("香蕉介面的成員函數");
    }
}
class Test
{
    static void Main()
    {
        IApple pApple=new Fruit ();//執行個體化介面類型的類
        pApple.circle ();
        pApple.spice ="香蘋果";
        Console.WriteLine (pApple.spice );
        
        IBanana pBanana=new Fruit ();
        pBanana.column ();
        pBanana.sweet ="甜香蕉";
        Console.WriteLine (pBanana.sweet );
        
        IApple pApp=new Fruit ();
        IBanana pBan=pApp as IBanana ;//介面查詢(QI),這裡其實就是一個顯式的強制轉換
        pBan.column ();
        pBan.sweet ="甜香蕉";
        Console.WriteLine (pBan.sweet );
    }
}從上面例子可以看出,QI其實是很好掌握的,原理非常簡單

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.