Autor Beitrag
foxy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 814

Ubuntu, Gentoo
C++, PHP, Java, Ruby, Perl (Eclipse)
BeitragVerfasst: Do 10.07.08 15:47 
Hi Leute,
gibts bei c# sowas wie eine parametererweiterung ?

also bei cpp kann man schreiben

ausblenden Quelltext
1:
public int test(string test, int test2, ...){ .....}					


also das man eine variable anzahl an paramtern hat

gruss

_________________
"Only wimps use tape backup: real men just upload their important stuff on ftp, and let the rest of the world mirror it." (Linus Torvalds)
OperatingSystem Laptop (Ubuntu Hardy)
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4798
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Do 10.07.08 16:30 
Ja, dafür gibt es das Schlüsselwort 'params':

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
public static void UseVariableParameters(params int[] list) 
{
     for ( int i = 0 ; i < list.Length ; i++ )
     {
        Console.WriteLine(list[i]);
     }
     Console.WriteLine();
}

public static void DemonstrateVariableParameters()
{
    Manager.UseVariableParameters(1,2,3,4,5);
}

Im obigen Beispiel kannst du also nur Zahlen (int) übergeben.
Wenn du beliebige Parameter übergeben willst, dann kannst du auch "params object[] list" verwenden.
foxy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 814

Ubuntu, Gentoo
C++, PHP, Java, Ruby, Perl (Eclipse)
BeitragVerfasst: Do 10.07.08 16:45 
ok vielen dank das habe ich gesucht !

_________________
"Only wimps use tape backup: real men just upload their important stuff on ftp, and let the rest of the world mirror it." (Linus Torvalds)
OperatingSystem Laptop (Ubuntu Hardy)