UrbanPro

Learn .Net Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

What is a partial class in .NET 2.0?

Asked by Last Modified  

1 Answer

Learn .Net

Follow 1
Answer

Please enter your answer

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...
read more

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:

  1. Definition Syntax:

    • To create a partial class, you use the 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.
    csharp
// File 1: MyClassPart1.cs partial class MyClass { // Part 1 of the class definition public void Method1() { /* ... */ } }
csharp
  1. // File 2: MyClassPart2.cs partial class MyClass { // Part 2 of the class definition public void Method2() { /* ... */ } }
  2. Combination at Compile Time:

    • When the code is compiled, the compiler combines all the partial class definitions into a single class. The resulting class has all the members and methods from each part.
  3. Use Cases:

    • Partial classes are often used in scenarios where code generation tools or designer-generated code needs to coexist with developer-written code. For example, Windows Forms and Web Forms in Visual Studio often use partial classes to separate auto-generated UI code from user-written logic.
  4. Benefits:

    • Provides a way to organize and separate large classes into logical parts, making it easier to manage code.
    • Enables code generation scenarios where one part of the class can be auto-generated, and another part can be manually written by developers.

Here's an example illustrating a partial class in .NET 2.0:

csharp
// File 1: MyClassPart1.cs partial class MyClass { public void Method1() { /* ... */ } }
csharp
// File 2: MyClassPart2.cs partial class MyClass { public void Method2() { /* ... */ } }
csharp
// 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.

 
 
read less
Comments

Related Questions

How is .Net core 1.1 different from .Net core 1.0?
Its show up gradation of .net Version with some more components.
Prabhu
0 0
5
I am new to ASP.Net MVC.I need to learn ASP.Net MVC .I need an Online training course for that.Kindly suggest a good online training website for ASP.Net MVC
Hi Shubhatra.. Many materials are available online for ASP.NET MVC course. You can find many tutorials videos. Try to make small projects using those tutorials,not just read or watch them. Remember best...
Shubhabrata
What is the difference between asp.net and vb.net?
asp.net is web technology that is used in building web applications and websites. Vb.net is language that is used in writing programs that are utilizing the asp.net framework Asp.net contains...
Aadarsh
How should I prepare IIt I'm in class 8th
You should start with basic programming like C & C++, this will help to make strong foundation of your career after that you could start any language training like .net, C#.net, java android etc...
Om
why we are using MVC instead of ASP.Net
MVC is not replacement of ASP.net but it is used along with ASP.net. It is architectural pattern with no code behind, no RAD controls, no ViewState, no ASP.net page life cycle etc to reduce burden on server and improve performance of webforms.
Mallikarjuna

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

OOPs Concepts
Session Objectives: Discuss the following: Drawbacks of traditional programming Need for Object: Oriented approach Object: Oriented techniques Discuss Object: Oriented Concepts Objects. Classes. Abstraction. Inheritance. Encapsulation. Polymorphism. Need...

CLR [ Common Language Runtime ] and it's properties
CLR is one of the components of the .NET framework which provides an environment to execute the .NET code or the managed code. , CLR helps in converting the MSIL/CIL code into native code and running...

Understanding Delegate in C# .NET
C# Delegate technique Delegate is one of the fantastic tool & technique in C#.NET. Using deleagte technique the following benefits could be avaialed One can define a method without name (Anonymous...

Angular-2 Developer Training Program Syllabus
Angular2 Developer Training Program Syllabus: Introduction to Angular2. Why Angular2. Angular2 Features: Components, Services and Typescript. Angular2 Components: Templates, Modules, Services...

Extension method In C#
Introduction. Hello Guys, In this article, I will explain what is extension method and why and where we should use this. Let’s understand the term extension means we are going to create something...

Recommended Articles

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,...

Read full article >

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...

Read full article >

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...

Read full article >

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...

Read full article >

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 you
X

Looking for .Net Training Classes?

The best tutors for .Net Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn .Net Training with the Best Tutors

The best Tutors for .Net Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more