Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Mono C# namespace declaration

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
Repesorsa
Posts: 22
Joined: 2018-03-24 10:21

Mono C# namespace declaration

#1 Post by Repesorsa »

Hi,

I'm a newbie with mono. This is my second C# script I've ever made with it:

Code: Select all

using System;

namespace RectangleApplication {
   class Rectangle {
      
      // member variables
      double length;
      double width;
      
      public void Acceptdetails() {
         length = 4.5;    
         width = 3.5;
      }
      public double GetArea() {
         return length * width; 
      }
      public void Display() {
         Console.WriteLine("Length: {0}", length);
         Console.WriteLine("Width: {0}", width);
         Console.WriteLine("Area: {0}", GetArea());
      }
   }
   class ExecuteRectangle {
      static void Main(string[] args) {
         Rectangle r = new Rectangle();
         r.Acceptdetails();
         r.Display();
         Console.ReadLine(); 
      }
   }
}
Program should print this:
  • Length: 4.5
    Width: 3.5
    Area: 15.75
When I try to execute the script nothing happens. Konsole just gives next empty line for writing.
But if I put this line and its square brackets into comments

Code: Select all

/*namespace RectangleApplication {

}*/
it works fine.

Is there some package I should add to have namespace declaration option? How necessary that is? Or should I care about it at all?
If I make a program for Windows which has no namespace declaration?

Repesorsa
Posts: 22
Joined: 2018-03-24 10:21

Re: Mono C# namespace declaration

#2 Post by Repesorsa »

Okay, now I'm confused... I tried the code again and it works fine with namespace declaration!

Post Reply