Developing a dotnet-c# Library

Bob 1 Reputation point
2021-07-10T23:01:10.123+00:00

I am trying to make a class library. So a sample code would be followed....

using System;
using CustomMath; //The parent library
using CustomMath.MathShapes.Shape1 // Child Library1
using CustomMath.MathShapes.Shape2; // Child library2

So let me clarify this more. First and foremost I know I would need to create a class library template. However, I don't know how to merge the child libraries to CustomMath. Do I make seperate libraries and then merge the 2 child libraries? If so then how do I merge them

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,204 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sam of Simple Samples 5,516 Reputation points
    2021-07-10T23:47:32.003+00:00

    Typically CustomMath would be your namespace and MathShapes would be a class in the namespace. Then Shape1 and Shape2 would be members of the class. All of that would use the same syntax as if they were in the same application that uses them except as a Class Library the class(es) can be shared by many applications. Typically you would not use the using statements for CustomMath.MathShapes.Shape1 and CustomMath.MathShapes.Shape2.

    If the preceding does not satisfy your requirements then please clarify what MathShapes , Shape1 and Shape2 are supposed to be in your application.

    0 comments No comments

  2. Karen Payne MVP 35,031 Reputation points
    2021-07-11T02:07:14.693+00:00

    See if this works for you, create to class projects, under project properties set the Default namespace to CustomMath under the Application tab, do the same for another class project.

    In the first class project create a folder named MathShapes, add a class named Shape1.cs

    using System;  
      
    namespace CustomMath.MathShapes  
    {  
        public class Shape1   
        {  
            public Shape1()  
            {  
                Console.WriteLine(nameof(Shape1));  
            }  
        }  
    }  
      
    

    Repeat for the second class project, this time

    using System;  
      
    namespace CustomMath.MathShapes  
    {  
        public class Shape2   
        {  
            public Shape2()  
            {  
                Console.WriteLine(nameof(Shape2));  
            }  
        }  
    }  
      
    

    For testing create a console project, add both above projects as references. Then use this code to test.

    using CustomMath.MathShapes;  
      
    namespace ConsoleApp1  
    {  
        class Program  
        {  
            static void Main(string[] args)  
            {  
                Shape1 shape1 = new Shape1();  
                Shape2 shape2 = new Shape2();  
                Console.ReadLine();  
            }  
        }  
    }  
    

    A visual of the above

    113583-figure1.png

    0 comments No comments