Namespace problem

BenTam-3003 686 Reputation points
2022-03-09T07:26:56.987+00:00

Dear All,

I create a function "String()" and put it into a separate file "library.cs" and assign the same "namespace NewTims" to it. However, if I paste it into the same page where the "String()" function resides, it works.

Library.cs
181343-library.gif

Error
181276-namespace.gif

Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 49,536 Reputation points
    2022-03-09T08:01:35.27+00:00

    The String method is a member of the Library class. To use the method without creating an instance of the Library class make it a static method. Then, you can call it within the FillDataListView method -- Library.String(" ", 100)


1 additional answer

Sort by: Most helpful
  1. Sreeju Nair 12,666 Reputation points
    2022-03-09T11:11:00.337+00:00

    String method you defined is a member function in the Library class. So you need to create the instance of Library class to call the String method.

    Library lib = new Library();
    lib.String(................);
    

    Since the method you used is not dependent on any property of Library class, making it a static function will simplify the function call.

    public static string String(.......)
    {
    
    }
    

    Now you can clall this method as below.

    Library.String(..........);
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.