Autor Beitrag
vit30
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: Mi 27.01.10 12:39 
Hallo!
Warum erhalte ich folgende Meldung:
"Typ- oder Namespace definition oder Dateiende erwartet"?
Alle Klammer sind da...
Code:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmalComp1
{
    class Program
    {
        static void Main(string[] args)
        {
#region methods
        private float Add(float firstValue,float secondValue)
        {
            float resultAdd = firstValue + secondValue;return resultAdd;
        }
        /*private float Substrah(float fistValue,float secondValue)
        {
        }
        private float Multiply(float firstValue, float secondValue) 
        {
        }
        private float Divide(float firstValue, float secondValue) 
        {
        }
         */

#endregion   
       
        ///<summary>Hier werden die Zahlen eingegeben, die berechnet
        ///werden müssen.
        ///</summary>
        private float addfirstValue(float firstValue)
        {
            Console.WriteLine("The first Small Computer from *lieber Vitalij*");
            Console.WriteLine("Geben Sie erste Zahl ein:");
            string a = Console.ReadLine();
            float a1 = float.Parse(a);
            return a1; 
        }
        private  float addSecondvalue(float secondValue)
        { 
            Console.WriteLine("Geben Sie zweite Zahl ein:");
            string b = Console.ReadLine();
            return float.Parse(b);

        }
        /// <summary>
        /// Auswahl von Rechnenfunktion
        /// </summary>
        /// <param name="firstValue"></param>
        /// <param name="secondValue"></param>
        /// <returns></returns>
        //try
   // {
        private void  makeChoise(int choise)
        {
            Console.WriteLine("Für Addieren drücken Sie die 1","\r\n");
            Console.WriteLine("Für Substrahieren drücken Sie 2","\r\n");
            Console.WriteLine("Fur Multiplizieren drücken Sie 3","\r\n");
            Console.WriteLine("Für Dividieren drücken Sie 4","\r\n");
            //string Achoise = Console.ReadLine();
            int choiseline = int.Parse(Console.ReadLine());
            
               
        
           switch (choiseline)
            {
                 case 1 :
                    //Aufruf Methode Add
                    float endResult = Add(addfirstValue(1),addSecondvalue(2)); 
                    break;
                 case 2 :
                    //Aufruf Methode Substrah
                    break;
                 case 3 :
                    //Aufruf Methode Multiply
                    break;
                 case 4 :
                    //Aufruf Methode Divide
                    break;
                 default :
                    
                    break;
                    
            }
           return;
            }
    
        }
    }
}
Nemag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 132
Erhaltene Danke: 2



BeitragVerfasst: Mi 27.01.10 12:51 
Du schließt deine MainMethode nicht bzw. erst am Ende was natürlich so nicht geht.


ausblenden C#-Quelltext
1:
2:
3:
static void Main(string[] args)
{
}
vit30 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: Mi 27.01.10 13:04 
user profile iconNemag hat folgendes geschrieben Zum zitierten Posting springen:
Du schließt deine MainMethode nicht bzw. erst am Ende was natürlich so nicht geht.


ausblenden C#-Quelltext
1:
2:
3:
static void Main(string[] args)
{
}

Und wo soll ich dann Methode schließen?
Wenn so wie du geschrieben hast, dann hört das Programm sofort auf zu laufen.
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Mi 27.01.10 13:10 
Schau genau hin: In Zeile 11 beginnt die Main-Methode, in Zeile 12 wird eine neue #region begonnen (das ist noch nicht schlimm, wenn auch ungewöhnlich), in Zeile 13 beginnt eine andere Methode. Verschachtelte Methoden sind unter C# nicht möglich; also muss zuerst die Main-Methode geschlossen werden, bevor die nächste begonnen werden kann.

Main ist von der Struktur her eine gewöhnliche Methode, steht also innerhalb der Klasse Program auf derselben Stufe wie die anderen Methoden. (Für einen Konstruktor gilt übrigens fast dasselbe.)

user profile iconvit30 hat folgendes geschrieben Zum zitierten Posting springen:
Wenn so wie du geschrieben hast, dann hört das Programm sofort auf zu laufen.

Innerhalb der Main-Methode musst du natürlich noch irgendetwas mit den anderen Methoden oder mit Variablen oder sonstwas machen.

Gruß Jürgen


Zuletzt bearbeitet von JüTho am Mi 27.01.10 13:11, insgesamt 1-mal bearbeitet
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 27.01.10 13:11 
Innerhalb deiner Main-Methode musst du natürlich den Quelltext schreiben, der da ablaufen soll. Also zum Beispiel dort deine anderen Funktionen aufrufen.
vit30 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: Mi 27.01.10 13:25 
Also soweit ist klar!
Danke!
Ich kämpfe weiter....
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Mi 27.01.10 13:27 
Willst du nun wirklich jeden banalen Kompilierfehler hier als Thread aufmachen?

Meistens Hilft ja schon der Kompilierfehler. Darüber hinaus kannst du ausprobieren, bis der Kompilierfehler weg ist. Wenn dir das nichts Hilft, solltest du mit den absoluten Grundlagen anfangen! Sprich mal in ein C# Programmierbuch schauen wir das Openbook C# vom Galileo Verlag.

Gruß Daniel