Autor Beitrag
Mitmischer 1703
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Di 01.12.09 17:26 
ausblenden Delphi-Prism-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var saveValue : Integer;
begin
  var List := new Dictionary<Char, Integer>;
  for i: Int32 := 0 to Input.Lines.Count-1 do begin
   for y: Int32 := 0 to Input.Lines[i].ToCharArray.Count-1 do begin
    var key := Input.Lines[i].ToCharArray[y];
    if List.ContainsKey(key) then
    begin
     List.TryGetValue(key, saveValue);
     List.Remove(key);
     List.Add(key, saveValue+1);
    end;
   end;  
  end;
end;


Hi DF :)

Ich muss euch leider wieder stören.

Ich habe eine Integer-Variable namens saveValue, die ich in List.TryGetValue(key, saveValue) als Variable einsetze - in diese soll er schreiben - er scheint aber nicht zu akzeptieren, dass ich diese Variable nur zu diesem Zweck geschaffen habe :evil: :

Fehler 1 (PE176) Modifizierer für Parameter "2" passt nicht: war [in] sollte out sein C:\Dokumente und Einstellungen\Max\Eigene Dateien\Visual Studio 2008\Projects\Project1\WindowsApplication5\WindowsApplication5\Main.pas 64 22 WindowsApplication5

_________________
Die Lösung ist nicht siebzehn.
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Di 01.12.09 17:34 
Anscheinend verlangt Prism wie C# ein var/out nicht nur bei der Deklaration, sondern auch beim Aufruf:
ausblenden Delphi-Prism-Quelltext
1:
List.TryGetValue(key, out saveValue);					

Aber wozu TryGetValue, wenn du davor schon ContainsKey aufgerufen hast? Ich denke, du meinst eigentlich folgendes:
ausblenden Delphi-Prism-Quelltext
1:
2:
3:
4:
5:
    var key := Input.Lines[i].ToCharArray[y];
    if List.TryGetValue(key, out saveValue) then
        List[key] := saveValue + 1
    else
        List.Add(key, 1);



Etwas lesbarer, außerdem wird ToCharArray nicht mehrmals pro Zeile aufgerufen:
ausblenden Delphi-Prism-Quelltext
1:
2:
for line in Input.Lines do begin
    for c in line.ToCharArray do begin

_________________
>λ=


Zuletzt bearbeitet von Kha am Di 01.12.09 17:39, insgesamt 1-mal bearbeitet
Mitmischer 1703 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Di 01.12.09 17:38 
Stimmt, vielen Dank!

Klappt!

_________________
Die Lösung ist nicht siebzehn.