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 f开发者_StackOverflowrom 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
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
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
精彩评论