Autor Beitrag
MiLaIm
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Sa 12.05.07 17:32 
Hi leute, bin neu hier und auch bei c# bin ich nicht all zu lange dabei.

Ich bin grad am lernen und da bin ich auf ein kleines problemchen gestossen.

Und zwar, ich will ein testprogramm mit Lottozahlen machen, die einfach generiert werden.

also, so sieht der quellcode vom button aus:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
private void btnGenerate_Click_1(object sender, EventArgs e)
        {
            int i;
            int[] Lotto;
            Lotto = new int[6];
            System.Random rand;
            rand = new System.Random();
            for (i = 0; i < 6; i++)
            {
                Lotto[i] = rand.Next() % 49 + 1;
            }
            lblText.Text = Lotto[i];
        }


Das Problem ist halt bei lblText.Text = Lotto[i];
Da bekomm ich diese fehlermeldung:

Cannot implicitly convert type 'int' to 'string'
Also das versteh ich schon aber convertierung nicht :-P

Danke im voraus für eure hilfe.


Moderiert von user profile iconChristian S.: Topic aus WinForms / WPF verschoben am Sa 12.05.2007 um 17:36


Zuletzt bearbeitet von MiLaIm am Sa 12.05.07 17:40, insgesamt 1-mal bearbeitet
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 12.05.07 17:37 
Also ich habe eigentlich ka von C#, aber es sieht alles danach aus, dass du einem String einen Integer zuweist.
Probiere mal, ob Lotto[i] eine Methode toString oder dergleichen bereitstellt. ( lotto[i].toString() )

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
MiLaIm Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Sa 12.05.07 17:54 
Marco Thx. Das hat das erste problem schonmal gelöst, die warnmeldung ist weg.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 12.05.07 17:54 
user profile iconMiLaIm hat folgendes geschrieben:
Marco Thx. Das hat das erste problem schonmal gelöst, die warnmeldung ist weg.

Kein Problem.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Sa 12.05.07 20:06 
Es existiert übrigens auch direkt die Methode Random.Next(1, 49). Dass Lottozahlen weder geordnet sind noch doppelt vorkommen, muss ich dir wohl nicht noch sagen ;) .
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 12.05.07 20:08 
user profile iconKhabarakh hat folgendes geschrieben:
Es existiert übrigens auch direkt die Methode Random.Next(1, 49).
Vorsicht, die Obergrenze von Random.Next() ist exklusive. Für die Zahlen von 1..49 brauchst Du also Random.Next(1,50)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Sa 12.05.07 20:14 
Hupsala, hätte nur bei Random.Next(x) daran gedacht. Das SDK ist aber auch mal wieder höchst verbose:
Zitat:
Random.Next (Int32) Returns a nonnegative random number less than the specified maximum.
Random.Next (Int32, Int32) Returns a random number within a specified range.
MiLaIm Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Sa 12.05.07 21:28 
Thx all. Nette kürzungen :D

Das mit dem ordnen und ob die zahl doppelt ist und so mach ich ja noch es ging nur um die anzeige. :-)