What is Partial types?

What is Partial types?

Partial Type:-C# 2.0 introduces the concept of a partial type declaration. This is quite simply a single type which spans multiple files, where each file declares the same type using the partial modifier. The files may refer to members declared within one another without problem (just as forward references within C# is already not a problem). 

Example:-
1st Part--
partial class Test
{
    string name;
    
    static void Main()
    {
        Test t = new Test("C# 2.0");
        t.SayHello();
    }
}
2ND PART:-

 using System;

partial class Test
{
    Test(string name)
    {
        this.name = name;
    }
    
    void SayHello()
    {
        Console.WriteLine ("Hi there. My name is {0}.", name);
    }
 
Compile with:

csc Test1.cs Test2.cs

Results:

Hi there. My name is C# 2.0.

By:kamal
Date:2012-10-10 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Links

C interview questions and answers for experienced and fresher