Pages

Wednesday, November 30, 2011

Internal and Protected Internal Difference

Internal and Protected Internal Difference:

Internal Scope will be, with in the assembly only and Protected Internal Scope can be outside of the assembly

Project 1:

using System;

using System.Collections.Generic;

using System.Text;

namespace InternalAssembly1

{

public class Program

{

static void Main(string[] args)

{

Console.WriteLine("Hi Assembly1");

Console.ReadLine();

baseClass obj = new baseClass();

obj.PIFunction();

obj.IFunction();

}

}

public class baseClass

{

protected internal void PIFunction()

{

Console.WriteLine("This is Assembly 1, I am in protected Internal");

Console.ReadLine();

}

internal void IFunction()

{

Console.WriteLine("This is Assembly 1, I am in Internal");

Console.ReadLine();

}

}

}

After that create a Assembly for that and add it’s reference to the project2

Project 2:

using System;

using System.Collections.Generic;

using System.Text;

namespace InternalAssembly2

{

using InternalAssembly1;

public class DrivedClass : baseClass

{

static void Main(string[] args)

{

Console.WriteLine("Hello Assembly 2");

DrivedClass obj = new DrivedClass();

obj.callPIFunction();

obj.callInternalFunction();

}

public void callPIFunction()

{

PIFunction();

}

public void callInternalFunction()

{

//IFunction(); // Compiler gives Error, since it doesnot have the accessiblity.

Console.WriteLine("Internal will not work");

Console.ReadLine();

}

}

}

No comments:

Post a Comment