Learn .Net Training from the Best Tutors
Search in
Partial classes were introduced in .NET 2.0 as a language feature that allows a single class to be defined in multiple files. Each file contains a part of the class definition, and all the parts are combined into a single class at compile time. This feature was introduced to facilitate code organization and separation of concerns.
Here are some key points about partial classes in .NET 2.0:
Definition Syntax:
partial
keyword in the class definition. Each part of the class is declared with the partial
keyword, and all parts must share the same class name.// File 1: MyClassPart1.cs partial class MyClass { // Part 1 of the class definition public void Method1() { /* ... */ } }
// File 2: MyClassPart2.cs partial class MyClass { // Part 2 of the class definition public void Method2() { /* ... */ } }
Combination at Compile Time:
Use Cases:
Benefits:
Here's an example illustrating a partial class in .NET 2.0:
// File 1: MyClassPart1.cs partial class MyClass { public void Method1() { /* ... */ } }
// File 2: MyClassPart2.cs partial class MyClass { public void Method2() { /* ... */ } }
// In another file or the same file // This is the combined class at compile time class Program { static void Main() { MyClass obj = new MyClass(); obj.Method1(); obj.Method2(); } }
In this example, MyClass
is defined in two separate files, and at compile time, the compiler combines them into a single class. The Main
method demonstrates calling methods from both parts of the class.
Related Questions
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Learn Hadoop and Big Data
Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...
Why Should you Become an IT Consultant
Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...
8 Hottest IT Careers of 2014!
Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...
Top 5 Skills Every Software Developer Must have
Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today. In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...
Looking for .Net Training ?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for .Net Training Classes are on UrbanPro
The best Tutors for .Net Training Classes are on UrbanPro