L
L
lotuzakim2021-08-31 17:51:09
C++ / C#
lotuzakim, 2021-08-31 17:51:09

How to specify a class in c#?

Good afternoon.
I ran into a problem when creating classes and methods in c#
I use the mono compiler

//MethodsTest.cs
using System;

namespace AAA
{
    class Program
    {
        static void Main(string[] args)
        {
            int result;
            FindingMax findingMax = new FindingMax();
            result = findingMax.MaxNumber(12, 14);
            Console.WriteLine(result);
        }
    }
}

//FindingMax.cs
using System;

namespace AAA
{
    class FindingMax
    {
        public int MaxNumber(int x, int y)
        {
            int result;
            if (x > y)
            {
                result = x;
            }
            else
            {
                result = y;
            }

            return result;
        }
    }
}

Compile errors:
MethodsTest.cs(10,13): error CS0246: The type or namespace name 'FindingMax' could not be found (are you missing a using directive or an assembly reference?)
MethodsTest.cs(10,41): error CS0246: The type or namespace name 'FindingMax' could not be found (are you missing a using directive or an assembly reference?)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-08-31
@vabka

You are compiling a single file.
I advise you to install the .NET SDK and create a project through it using dotnet new console .
612e4e667faf5150731479.png
csc should not be used directly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question