I am working on C# encapsulation from Tutorialspoint.com. And I read this
What is the difference between Public, Private, Protected, and Nothing?1question from Stackoverflow. I read answer and i understood access specifiers in teoric. Now I want to make console application with this subject in visual studio.
public
The type or member can be accessed by any other code in the same assembly or another assembly that references it.
private
The type or member can only be accessed by code in the same class or struct.
protected
The type or member can only be accessed by code in the same class or struct, or in a derived class.
internal
The type or member can be accessed by any code in the same assembly, but not from another assembly.
protected internal
The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly.
Variables or methods with public access specifier are accessed from same assembly and different assembly. But this station is different in internal description. Internal types variables and methods can accessed only same assembly but not different assembly in c#. I want to test this station in C#.So that i create two project and call method or variables between each other.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TutorialsPoint.Encapsulation
{
public class PublicEncapsulation
{
//member variables
public double length;
public double width;
public double GetArea()
{
return length * width;
}
public void Display()
{
Console.WriteLine("Length: {0}", length);
Console.WriteLine("Width: {0}", width);
Console.WriteLine("Area: {0}", GetArea());
}
}
}
Above code is my 'PublicEncapsulation.cs' and i should call its members from other assembly.My other assembly project's class is Program.cs. I want to connect PublicEncapsulation.cs's members from Program.cs(other assembly). How can i do this calling operation from other assemblies in c#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using System.Collections;
namespace CallOtherAssemblyVariablesOrMethods
{
class Program
{
static void Main(string[] args)
{
/*Call PublicEncapsulation.cs's members in there.*/
}
}
}
Above class is Program.cs. I want to call other asssembly PublicEncapsulation.cs's members in here.
2 days ago i have an simple problems. I solved my my problems with Stackoverflow. I wanted to see difference between internal and public access specifier. And then i created two project to see difference of them. If i could call public methods and couldn't call internal methods from other assembly and then theoretical knowledge is supported with C# console application. I wanted to do this. But i can't see other project's public members. And then i found solution in this How to use a Class from one C# project with another C# project tutorial. I should have added reference in project with right click.
Many thanks to everyone...