클래스 개체를 반환하는 C#에서 DLL이 있습니다.dll에서 클래스 개체 반환 C#
DLL 코드 :
Person.cs :
namespace Extract
{
public class Person
{
public string name;
public string address;
public int age;
public int salary;
}
}
Class1.cs를
namespace Extract
{
public class MClass
{
public static Person GetPerson()
{
Person p = new Person();
p.name = "Deepak";
p.address = "Bangalore";
p.age = 30;
p.salary = 20000;
return p;
}
}
}
내가 같은 사람을 가지고 C#에서 다른 프로그램 "RunApp"가 .cs 클래스를 만들고 위의 dll에서 개체를 가져 오려고합니다.
RunApp 코드 :
Person.cs :
namespace Extract
{
public class Person
{
public string name;
public string address;
public int age;
public int salary;
}
}
에서 Form1.cs :이 후
namespace Ex
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Person mem = MClass.GetPerson();
}
}
}
, 나는 "RunApp"코드를 컴파일 할 때, I 오류 발생 :
"Cannot implicitly convert type 'Extract.Person' to 'Ex.Person' ". I tried changing the namespace of the "RunApp" code from 'Ex' to 'Extract', but too the same Error: "Cannot implicitly convert type 'Extract.Person' to 'Extract.Person' ".
Extract.dll에서 RunApp 프로그램으로 값을 보내려고합니다. 여러 프로그램에서이 DLL을 사용하고 싶습니다.
누구든지이 문제를 해결하는 방법을 도울 수 있습니까?
질문과는 관계가 없지만 공개 필드는 권장하지 않습니다 ... 각각의 끝에 {{get; set;} '을 추가하는 것이 좋습니다. –