如何将一个类的属性用于另一个类 [英] How to use properties of one class into another class
问题描述
错误:
if(C!= null)
{
C =新CRfD( )
{
CN = this.C.ToString(),
CId = new Guid(9c9aa88783fe5118f302)
};
我尝试过:
if(C!= null)
{
C = new CRefDt()
{
CN = this.C.ToString(),
CId = new Guid(9c9aa88783fe5118f302)
};
如你所说,你的class1和class2在一个项目中。 class3在另一个项目中。
从我的知识中,class1和class2应该在classlibrary应用程序中。这样你就可以将该项目的dll添加到你需要的任何地方。
ConsoleApplication:
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 ClassLibrary1;
使用 ClassLibrary2;
命名空间 ConsoleApplication2
{
class 计划
{
public void print()
{
Console.WriteLine( print);
}
静态 void Main( string [] args)
{
Class1 c = new Class1();
c.disp();
Class2 c1 = new Class2();
c1.supply();
Console.WriteLine( consoleapplication2);
Console.Read();
}
}
}
ClassLibrary:
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
命名空间 ClassLibrary1
{
public class Class1
{
public void disp()
{
Console.WriteLine( Jiii );
}
}
}
控制台应用程序中的class2是一个不同的类库。
Error:
if (C != null)
{
C = new CRfD()
{
CN = this.C.ToString(),
CId = new Guid("9c9aa88783fe5118f302")
};
What I have tried:
if (C != null)
{
C = new CRefDt()
{
CN = this.C.ToString(),
CId = new Guid("9c9aa88783fe5118f302")
};
As you said, your class1 and class2 are in one project. class3 is in another project right.
From my Knowledge, class1 and class2 should be in a classlibrary application. So that you can add the dll of that project to wherever you needed.
ConsoleApplication: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ClassLibrary1; using ClassLibrary2; namespace ConsoleApplication2 { class Program { public void print() { Console.WriteLine("print"); } static void Main(string[] args) { Class1 c = new Class1(); c.disp(); Class2 c1 = new Class2(); c1.supply(); Console.WriteLine("consoleapplication2"); Console.Read(); } } } ClassLibrary: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public class Class1 { public void disp() { Console.WriteLine("Jiii"); } } }
class2 in console application is a different class library.
这篇关于如何将一个类的属性用于另一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!