簡體   English   中英

Visual Studio 2010中的代碼分析警告-CA1007

[英]Code Analysis Warnings in Visual Studio 2010 - CA1007

我已在規則集中將CA1007設置為“錯誤”。 然后,我編寫了以下代碼來違反此規則,但仍未將其檢測為警告或錯誤。 不確定我在哪里出錯,是在代碼中還是在規則集中?

class Program
{
    public static void Swap(ref object object1, ref object object2)
    {
        object temp = object1;
        object1 = object2;
        object2 = temp;
    }

    static void Main(string[] args)
    {
        string string1 = "Swap";
        string string2 = "It";

        object object1 = (object)string1;
        object object2 = (object)string2;
        Program.Swap(ref object1, ref object2);
        string1 = (string)object1;
        string2 = (string)object2;
        Console.WriteLine("{0} {1}", string1, string2);

        Console.ReadLine();
    }
}

有什么建議么? 謝謝!

由於Program是私有類(它上沒有修飾符,因此默認為私有),因此從外部看不到public static方法。 CA1007旨在確保公共API使用良好的簽名,但內部,私有和其他不可見方法不受此規則CA1007

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM