question

Bob-0347 avatar image
0 Votes"
Bob-0347 asked karenpayneoregon answered

Developing a dotnet-c# Library

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


dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SimpleSamples avatar image
0 Votes"
SimpleSamples answered

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.






5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered

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




figure1.png (15.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.