A partial class is a class whose definition is present in 2 or more files. Each source file contains a section of the class, and all parts are combined when the application is compiled. To split a class definition, use the partial keyword as shown in the example below. Student class is split into 2 parts. The first part defines the study() method and the second part defines the Play() method. When we compile this program both the parts will be combined and compiled. Note that both the parts uses partial keyword and public access modifier.
using System;
namespace PartialClass
{
public partial class Student
{
public void Study()
{
Console.WriteLine("I am studying");
}
}
public partial class Student
{
public void Play()
{
Console.WriteLine("I am Playing");
}
}
public class Demo
{
public static void Main()
{
Student StudentObject = new Student();
StudentObject.Study();
StudentObject.Play();
}
}
}
It is very important to keep the following points in mind when creating partial classes.
1. All the parts must use the partial keyword.
2. All the parts must be available at compile time to form the final class.
3. All the parts must have the same access modifiers - public, private, protected etc.
4. Any class members declared in a partial definition are available to all the other parts.
5. The final class is the combination of all the parts at compile time.
My Blog List
Sponser Link
know more info pls click here
Subscribe to:
Post Comments (Atom)
Popular Posts
-
<div id="editable" contenteditable="true"> text text text<br> text text text<br> text text...
-
1. Use exception-handling structures to deal with exceptions within the scope of a procedure. This technique is called structured exception ...
-
There is a little tool called JSPExecutor that allows you to do just that. The developers (Hendrik Schreiber <hs@webapp.de> & Pet...
-
The Trace object provides the Write and Warn methods to allow you to write messages to a request’s trace information. The two methods are id...
-
Let me explain the process; 1. First you should go to your adsense account and grab the code for your adsense ads. 2. For this you sh...
-
Few know that those who have web hosting are at the same time endowed with a free VPN (Virtual Private Network, a very safe connection to t...
-
There are a number of ways to get information about a particular Linux command. Chances are you are using bash shell which is currently the...
-
To check if a URL or an email address is valid, the common solution is regular expressions. For instance, to validate an email address in P...
-
we are running a classified site and the latest ads which are coming to the system is indexed in solr write server in every three minutes. T...
-
open source Apache webserver is well-proven, but can still offer an administrator headaches from timeto time when things don't go quite ...
0 comments:
Post a Comment