将集合属性与成员对象一起使用

编程入门 行业动态 更新时间:2024-10-27 02:18:06
本文介绍了将集合属性与成员对象一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我有一个集合,说 Cells ,如果引用像 Cells [1,1] 给我一个该集合的对象,但成员对象没有该集合对象具有的某个属性。有没有办法从成员调用该属性?如下,假设 StartPosition 是集合的对象类的属性:

Cells [1,1] .StartPosition

或者

<

Cells [1,1] .ParentCollection.StartPosition

解决方案

您只能调用在您正在访问的对象上定义的属性。

也就是说,如果要调用集合上的方法,请在集合上调用,

您可以 可以添加对包含集合的引用到您放置的每个项目,如果您设计

您的符号是数组符号,用于2维数组。虽然数组是集合,但大多数.NET集合不被视为数组,即使它们有 indexers 。

If I have a collection, say Cells, and if referenced like so Cells[1,1] it gives me an object of that collection but the member object doesn't have a certain property that the collection object has. Is there a way to call that property from the member? Like as follows, assuming StartPosition is a property of the object class for the collection:

Cells[1,1].StartPosition

or maybe

Cells[1,1].ParentCollection.StartPosition

解决方案

You can only call properties that are defined on the object you are accessing.

That is, if you want to call a method on the collection, call it on the collection, not on the content of the collection.

You could add a reference to the containing collection to each item you put in it, if you design and construct your classes that way.

Note:

Your notation is array notation, for 2 dimensional arrays. Though arrays are collections, most .NET collections are not considered to be arrays, even if they do have indexers.

更多推荐

将集合属性与成员对象一起使用

本文发布于:2023-11-22 00:21:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615248.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   对象   成员

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!