Autor Beitrag
hui1991
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 433

Windows XP, WIndows Vista
Turbo Delphi Explorer| Delphi, PHP,Blitzbasic
BeitragVerfasst: Mi 27.08.08 09:28 
Hallo,

ich hab folgendes Problem:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure Wert(var s: String);
begin
  s := 'Test';
end;

procedure TForm1.Button1Click(Sender: TObject);
var 
  s: String;
begin
  s = '';
  Wert(s);
  //Hier ist s = "Test"
end;


Das will ich haben, wenn ich es aber in C# mache, dann fehlt mir das markierte var.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
public void Wert(string s)
{
  s = "Test";
}

public void Main(...)
{
  string s = "";
  Wert(s);
  //Hier ist s = ""
}


Was habe ich vergessen? Kann man das eigentlich so machen?
var habe ich schon probiert, aber gibt es nicht.


Moderiert von user profile iconChristian S.: Topic aus Sonstiges (.NET) verschoben am Mi 27.08.2008 um 12:09
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Mi 27.08.08 09:47 
out und ref sind deine Freunde.

ausblenden C#-Quelltext
1:
2:
3:
4:
public void Wert(out string s)
{
  s = "Test";
}
hui1991 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 433

Windows XP, WIndows Vista
Turbo Delphi Explorer| Delphi, PHP,Blitzbasic
BeitragVerfasst: Mi 27.08.08 09:52 
Danke =)

Funktioniert sofort.