הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   עזרה ב C# (https://hosts.co.il/forums/showthread.php?t=31274)

Elad-A 22-09-06 09:34

עזרה ב C#
 
לאיפה אני אמור להיכנס בתוכנה כדי להכניס את הקודים ולהריץ אותם?
למשל יש את הקוד הבא: (המחשבון שרותם עשה)
קוד:

using System;
using System.Collections.Generic;
using System.Text;

namespace Calculator
{
    class Program
    {
        static void Main(string[] args)
        {
            int A;
            int B;
            char C;

            Console.WriteLine("Welcome to C# calculator!");
            Console.WriteLine("Made by Rotem the programmer :P");

            Console.WriteLine();

            Console.Write("Please insert the first number: ");
            A = int.Parse(Console.ReadLine());

            Console.Write("Please insert the second number: ");
            B = int.Parse(Console.ReadLine());

            Console.Write("Please insert an action: ");
            C = char.Parse(Console.ReadLine());

            if ((C == '/') || (B == 0))
            {
                Console.WriteLine();
                Console.WriteLine("You can't division by zero!");
                Console.Read();
            }

            else
            {
                switch (C)
                {
                    case '+':
                        Console.WriteLine("The Result: {0} {1} {2} = {3}", A, C, B, A + B);
                        Console.Read();
                        break;

                    case '-':
                        Console.WriteLine("The Result: {0} {1} {2} = {3}", A, C, B, A - B);
                        Console.Read();
                        break;

                    case '*':
                        Console.WriteLine("The Result: {0} {1} {2} = {3}", A, C, B, A * B);
                        Console.Read();
                        break;

                    case '/':
                        Console.WriteLine("The Result: {0} {1} {2} = {3}", A, C, B, A / B);
                        Console.Read();
                        break;

                    default:
                        Console.WriteLine("There is a problem! :(");
                        break;
                }
            }
        }
    }
}

תודה למי שיעזור..

lalamen 22-09-06 09:42

File-> New Project...
תבחר שם Console Application
תכניס את הקוד ואז תעשה
Debug-> Start Debugging

omaniusd 22-09-06 09:56

ואם יש לך רק את הSDK (בלי סביבת הפיתוח), תריץ את הפקודה הזאת בקונוסולה ( a.cs שם הקובץ):
קוד:

csc a.cs

Elad-A 22-09-06 10:09

הצלחתי תודה. מה הבעיה בקוד הזה?

PHP קוד:


using System
;
using System.Collections.Generic;
using System.Text;

namespace test
{
    class 
Program
    
{
        static 
void Main(string[] args)
        {
            
char A;

            
Console.WriteLine("test page");
            
Console.WriteLine();
            
Console.Write("enter your name: ");
            
char.Parse(Console.ReadLine());
            
Console.WriteLine("your name is: {0}"A);
            
Console.Read();
        }
    }


זה מציג לי הודעה של "דו"ח שגיאות"

omaniusd 22-09-06 10:35

ציטוט:

נכתב במקור על ידי Elad-A
הצלחתי תודה. מה הבעיה בקוד הזה?

PHP קוד:


using System
;
using System.Collections.Generic;
using System.Text;

namespace test
{
    class 
Program
    
{
        static 
void Main(string[] args)
        {
            
char A;

            
Console.WriteLine("test page");
            
Console.WriteLine();
            
Console.Write("enter your name: ");
            
char.Parse(Console.ReadLine());
            
Console.WriteLine("your name is: {0}"A);
            
Console.Read();
        }
    }


זה מציג לי הודעה של "דו"ח שגיאות"

למה יש Console.WriteLine ריק?

Elad-A 22-09-06 10:38

התבלבלתי שם.
תשמע שיפרתי קצת את הקוד.

PHP קוד:


using System
;

namespace testConsole
{
    public class 
Test
    
{
        public static 
void Main()
        {
            
string str;
            
Console.WriteLine("Test Page By Elad-A");
            
Console.Write("Enter Your Name: ");
            
str Console.ReadLine();
            if (
str == "")
            {
                
Console.Write("Enter Your Name!");
            }
            else
            {
                
Console.Write("Hello, {0}"str);
            }
            
Console.Read();
        }
    }


לא הצלחתי לעשות שאם str ריק זה יציג שוב פעם את הטופס להכנסת השם.
וד"א איך מיצאים כקובץ EXE?

omaniusd 22-09-06 10:45

ציטוט:

נכתב במקור על ידי Elad-A
התבלבלתי שם.
תשמע שיפרתי קצת את הקוד.

PHP קוד:


using System
;

namespace testConsole
{
    public class 
Test
    
{
        public static 
void Main()
        {
            
string str;
            
Console.WriteLine("Test Page By Elad-A");
            
Console.Write("Enter Your Name: ");
            
str Console.ReadLine();
            if (
str == "")
            {
                
Console.Write("Enter Your Name!");
            }
            else
            {
                
Console.Write("Hello, {0}"str);
            }
            
Console.Read();
        }
    }


לא הצלחתי לעשות שאם str ריק זה יציג שוב פעם את הטופס להכנסת השם.
וד"א איך מיצאים כקובץ EXE?

תפריד חלק מהפעילות למתודה אחרת וקרא לה.
קובץ EXE יהיה אחרי שתעשה build בתיקייה bin של האפליקציה.

Elad-A 22-09-06 10:51

לא ממש הבנתי אותך אבל ניסיתי משהו אחר והוא לא עובד (אין שגיאות)

PHP קוד:


using System
;

namespace testConsole
{
    public class 
Test
    
{
        public static 
void Main()
        {
            
string A;
            
string B;
            
Console.WriteLine("Test Page By Elad-A");
            
Console.Write("Enter Your Name: ");
            
Console.ReadLine();
            
Console.Write("Enter Your Last Name: ");
            
Console.ReadLine();

            if (
== "" || == "")
            {
                
Console.Write("Empty Fields");
            }
            else
            {
                
Console.Write("Hello, {0} (1)"A,B);
            }
            
Console.Read();
        }
    }


זה לא מציג את ה last name (משתנה B)

omaniusd 22-09-06 11:39

1 גם צריך להיות בסוגריים מסולסלות {1}


כל הזמנים הם GMT +2. הזמן כעת הוא 01:52.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ