English 中文(简体)
初步确定时的特性
原标题:Specifying properties when initialising
void Foo()
{

string ID = "test";
var testctrl = new Control() {ID = (ID**!=null?ID**:ID)};

}

能否将ID**的价值纳入上述法典? 问题是他们都有相同的财产名称。

请忽视这样一个事实,即身份证的具体转让是毫无意义的,只是将其作为一个例子。

最佳回答

Putting aside that the code can t possibly compile... The first ID (ID=) in this syntax refers to the assignment, specifically the member being assigned. On the right-hand-side, it comes down to standard resolution. Which never means the ID of the new object. It will first look at the local ID variable, then after that members (fields etc) on the current instance. To prefer members on the current instance, use this.ID.

您也不妨考虑取消销售的经营人,这样,如果你指的是“当地负债者,或者如果无效的话,那将是? . . .

问题回答

首先对这条线说几句,它看着奇怪的(把铺设为ool):

bool ID = "test";

第二点是,这部作品是:

string ID = "test";
var testctrl = new Control(){ ID = (ID==null?ID:ID) };

第三点:它是在C#中的一项公约,用下级文字来标明您的地方变量。

如果你想要检查新的控制是否无效,那么你应该这样做。

void Foo()
{
    string ID = "test";
    var testctrl = new Control();
    if(testctrl.ID==null)
        testctrl.ID = ID;
}

问题不是我所清楚的,而是你们想要做到:

void Foo()
{

bool ID = "test";
var testctrl = new Control(){ID = (this.ID==null?ID:this.ID)};

}

注:未经测试。

Seeing your example, I suspect that you don t have the requirement that the ID should be unique? In general, to avoid nasty problems like this, avoid try using duplicate property names, but maybe your bound to an existing interface.

• 如何增加一个将外部识别作为参数的构件超负荷?

void Foo()
{

string ID = "test";
var testctrl = new Control(ID);

}

我认为,一般而言,如果财产不仅仅只是转让(在这种情况下进行清点检查),那么你就应当在一套财产本身,而不是在标的初始阶段这样做。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签