Wie kann ich Attribut einer Methode in eine andere Methode verwenden?Attribut einer Methode in eine andere Methode verwenden
zum Beispiel: (i kommentiert in verwandten Linien)
ich habe
public int merge()
{
string[] source = textBox3.Text.Split(',');
int[] nums = new int[source.Length];//i want to use nums in mergesort() too,how can i do that?
for (int i = 0; i < source.Length; i++)
{
nums[i] = Convert.ToInt32(source[i]);
}
}
und
public int mergesort()
{
if (nums.Length > 1)///i wrote nums here but compiler doesnt know what nums is.
{
int n = nums.Length;
int p = (int)Math.Floor(n/2.0);
int m = n - p;
List<int> lst1 = new List<int>();
lst1.AddRange(nums.Skip(n/2));
List<int> lst2 = new List<int>();
lst2.AddRange(nums.Take(n/2));
}
Attribute eine andere Bedeutung in C# ... –
Korrekte Verwendung der Nomenklatur ist wichtig, sich verständlich zu machen. Was nums in Ihrem Code ist, ist eine "Variable". –
FYI - http://msdn.microsoft.com/en-us/library/system.attribute.aspx –