![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
![]() Grupa: Zarejestrowani Postów: 654 Pomógł: 17 Dołączył: 19.03.2006 Skąd: z kosmosu ;) Ostrzeżenie: (0%) ![]() ![]() |
Witam, uczę się C# z kursu centrumxp.pl i mam problem z tym kodem (sam napisałem bez pomocy... ale za to jest gdzieś błąd):
Kod using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestProgram { class Program { static void Main() { // Variables int[] Numbers = new int[2]; int Match; bool Fail = false; string Action; string ActionName; // What do you want to do? System.Console.WriteLine("Co chcesz zrobic:\n1. Dodac\n2. Odjac\n3. Pomnozyc\n4. Podzielic"); Action = System.Console.ReadLine(); // Get two numbers System.Console.WriteLine("Podaj liczbe nr.1:"); Numbers[0] = System.Convert.ToInt32(System.Console.ReadLine()); System.Console.WriteLine("Podaj liczbe nr.2:"); Numbers[1] = System.Convert.ToInt32(System.Console.ReadLine()); // Selecting action switch (Action) { case "1": ActionName = (string)"dodawania"; Match = Numbers[0] + Numbers[1]; break; case "2": ActionName = (string)"odejmowania"; Match = Numbers[0] - Numbers[1]; break; case "3": ActionName = (string)"mnozenia"; Match = Numbers[0] * Numbers[1]; break; case "4": ActionName = (string)"dzielenia"; Match = Numbers[0] / Numbers[1]; break; default: Fail = true; break; } if (Fail == false) System.Console.WriteLine("Wynik "+ActionName+": "+Match); else System.Console.WriteLine("Nie poprawna akcja wybrana."); } } } Cytat Error 1 Use of unassigned local variable 'ActionName' C:\Documents and Settings\*\Ustawienia lokalne\Dane aplikacji\Temporary Projects\TestProgram\Program.cs 53 51 TestProgram Error 2 Use of unassigned local variable 'Match' C:\Documents and Settings\*\Ustawienia lokalne\Dane aplikacji\Temporary Projects\TestProgram\Program.cs 53 67 TestProgram @edit W C# Mogę używać MySQL? @edit Jaka funkcja sprawdza czy argument jest liczbą/ciągiem itp (PHP: is_string(), is_int(), is_array() itp.)? Dziękuję, Babcia@Stefa Ten post edytował Babcia@Stefa 24.06.2008, 09:40:39 -------------------- Środowisko testowe (desktop) - Gedit, lighttpd, sftp, rsync, xfce4-terminal, chromium, firefox4 | System: Gentoo ~x86
O'Neill - serwer WWW @ lighttpd, links, nano, rsyncd, sftpd | System: Debian ![]() |
|
|
![]()
Post
#2
|
|
![]() Grupa: Moderatorzy Postów: 36 557 Pomógł: 6315 Dołączył: 27.12.2004 ![]() |
jak glosi komunikat uzywasz nie okreslonej (nie podales dla niej wartosci) zmiennej.
Dla ActionName przypisujesz wartosc w switch, ale w tym switch nie dales nic dla default, czyli teroretycznie ActionName moze nie byc nigdy okreslone. Podobnie ma sie Match. -------------------- "Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista "Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer |
|
|
![]()
Post
#3
|
|
![]() Grupa: Zarejestrowani Postów: 654 Pomógł: 17 Dołączył: 19.03.2006 Skąd: z kosmosu ;) Ostrzeżenie: (0%) ![]() ![]() |
Dzięki nospor działa poprawnie
![]() @edit W C# Mogę używać MySQL? @edit Kod using System;
using System.Collections.Generic; using System.Linq; using System.Text; namespace TestProgram { class Program { static void Main() { // Variables int[] Numbers = new int[2]; int Match; bool Fail = false; string Action; string ActionName; // What do you want to do? System.Console.WriteLine("Co chcesz zrobic:\n1. Dodac\n2. Odjac\n3. Pomnozyc\n4. Podzielic"); Action = System.Console.ReadLine(); // Please give the two numbers System.Console.WriteLine("Podaj liczbe nr.1:"); Numbers[0] = System.Convert.ToInt32(System.Console.ReadLine()); System.Console.WriteLine("Podaj liczbe nr.2:"); Numbers[1] = System.Convert.ToInt32(System.Console.ReadLine()); // Selecting action switch (Action) { case "1": ActionName = (string)"dodawania"; Match = Numbers[0] + Numbers[1]; break; case "2": ActionName = (string)"odejmowania"; Match = Numbers[0] - Numbers[1]; break; case "3": ActionName = (string)"mnozenia"; Match = Numbers[0] * Numbers[1]; break; case "4": ActionName = (string)"dzielenia"; Match = Numbers[0] / Numbers[1]; break; default: Fail = true; ActionName = "brak"; Match = 0; break; } if (Fail == false) System.Console.WriteLine("Wynik "+ActionName+": "+Match); else System.Console.WriteLine("Nie poprawna akcja wybrana."); System.Console.Read(); Main(); } } } Ten post edytował Babcia@Stefa 24.06.2008, 09:35:57 -------------------- Środowisko testowe (desktop) - Gedit, lighttpd, sftp, rsync, xfce4-terminal, chromium, firefox4 | System: Gentoo ~x86
O'Neill - serwer WWW @ lighttpd, links, nano, rsyncd, sftpd | System: Debian ![]() |
|
|
![]()
Post
#4
|
|
![]() Grupa: Moderatorzy Postów: 2 921 Pomógł: 269 Dołączył: 11.08.2005 Skąd: 127.0.0.1 ![]() |
Nie żebym się czepiał, ale do C# są inne fora. Polecam codeguru.pl.
A co do pytania - tak można używać mysql z c#. Musisz mieć sterownik odbc (lub oledb - nie pamiętam teraz który, dawno już nie pisałem w c#) do mysql-a. -------------------- I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features. |
|
|
![]() ![]() |
![]() |
Wersja Lo-Fi | Aktualny czas: 18.07.2025 - 17:17 |