我不太了解房产.代码行:method2(x.str1,x.str2,x.str3,x.str4); ---抛出一个"对象引用未设置为对象错误的实例".任何想法都赞赏.x.str1没有解决?
(我正在添加一些代码并为现有设置添加更多功能.我会使用方法和属性初始化类myProperty.)
使用otherC#
class Test{
private myProperty x;
private string str1, str2, str3, str4;
private myProperty A
{
get { return x; }
set
{
str1 = value.str1;
str2 = value.str2;
str3 = value.str3;
str4 = value.str4;
}
}
public void myMethod()
{
Test tst = new Test();
myProperty x = new myProperty();
//Assigning property varaibles:
x.str1 = "this";
x.str2 = "is";
x.str3 = "my";
x.str4 = "test";
try
{
tst.method2(x.str1, x.str2, x.str3, x.str4);
}
catch(Exception)
{
throw;
}
}
public void method2(string str1, string str2,string str3, string str4)
{
}
}
OtherC#.cs contains the definition for myProerty class
namespace temp
{
public class xyx {some code;}
public interface abc {some code};
public class myProperty {
public string str1 { get; set; }
public string str2 { get; set; }
public string str3 { get; set; }
public string str4 { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
myProperty x 调用时未设置为对象的实例
x.str1 = "this";
Run Code Online (Sandbox Code Playgroud)
您必须首先初始化它(例如,在构造函数代码中).
| 归档时间: |
|
| 查看次数: |
218 次 |
| 最近记录: |