Mono C# namespace declaration

Need help with C, C++, perl, python, etc?

Mono C# namespace declaration

Postby Repesorsa » 2018-05-07 17:36

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

Postby Repesorsa » 2018-05-07 17:54

Okay, now I'm confused... I tried the code again and it works fine with namespace declaration!
Repesorsa
 
Posts: 22
Joined: 2018-03-24 10:21


Return to Programming

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable