Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can we inherit a class from one project to another in c# windows application

can we inherit frm a class in different project in c# windows application. I have a class in a project A the class in A has methods to print a doc apart from getting document to print etc.I need to separate the printing method from project A and put it in2 project b so that we can separate the gui part.Can any one tell me how to do that or provide an example if you have 1.. I create a new project under the same solution explorer but not sure what and how to do next

like image 247
laura Avatar asked Oct 27 '25 04:10

laura


2 Answers

Why not create a class library (dll) with the objects, and include it in both projects? That's common for anything you find yourself sharing among other [independant] projects.

MySolution
├ Project.PrintingLibrary
│ └ PrintingLibrary.cs
├ Project.ApplicationA
│ └ References
│   └ Project.PrintingLibrary.dll
├ Project.ApplicationB
│ └ References
│   └ Project.PrintingLibrary.dll
like image 148
Brad Christie Avatar answered Oct 29 '25 20:10

Brad Christie


In Project B, add a reference to Project A. Create a new class in Project B, and specify that it inherits from the class in Project A as shown:

C#:

public class ClassB : ProjectA.ClassA    
{
//...
}

VB.Net:

Public Class ClassB
    Inherits ProjectA.ClassA
    '...
End Class
like image 20
Rick Liddle Avatar answered Oct 29 '25 20:10

Rick Liddle