Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How I can refer to the class in another file of C# project

+2 votes
asked Jul 1, 2021 by Вячеслав Перевышин (140 points)
Please tell me how I can refer to the class in another file of C# project (at onlinegdb.com) . Tried to use the word "Using" with corresponding namespace, but it gives a message that the class is not available.

1 Answer

0 votes
answered Sep 23, 2021 by Peter Minarik (55,660 points)

Everything that belongs to the same compilation unit is visible to everything else in the same compilation unit. You don't need to "include" a class.

Consider this:

Person.cs

internal class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
    
    public override string ToString() => $"Person{{name: {Name}, age: {Age}}}";
}

Main.cs

using System;

internal class HelloWorld
{
    static void Main()
    {
        Console.WriteLine(new Person { Name = "Tobias Moretti", Age = 61 });
    }
}

This code compiles and works. In Main.cs I can use my Person class just fine.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...