为什么我不必在行Dim子节点中将New用作TreeNode [英] Why don't I have to use New in the row Dim subnode As TreeNode

查看:141
本文介绍了为什么我不必在行Dim子节点中将New用作TreeNode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我想知道,为什么声明子节点时不必像声明节点时那样使用New.我知道我在Dim节点行中使用TreeNode的构造函数之一作为New TreeNode(&"面向对象的编程语言),但是我不明白为什么我可以在不使用子节点的情况下使用声明时使用New.

Hi I''m wondering, why I don''t have to use New when declaring subnode as I do when when declaring node. I know I''m using one of the TreeNode''s constructors in the line Dim node As New TreeNode("Object Oriented Programming Languages"), but I don''t understand why I can use subnode without using New when declaring it.

Private Sub MyForm_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
    treeView1.Nodes.Clear()
    treeView1.Nodes.Add("Programming Languages")
'' --->
    Dim node As New TreeNode("Object Oriented Programming Languages")
    node.Nodes.Add("C++")
    Dim subnode As TreeNode = node.Nodes.Add("Framework and runtime based languages")
'' <---
    subnode.Nodes.Add("Java")
    subnode.Nodes.Add("C#");
    treeView1.Nodes(0).Nodes.Add(node)
End Sub




请帮助我理解这一点.可能很容易,但是我需要一个解释.

谢谢
国际汽联

[edit]下划线已删除-在代码块中效果不佳! -OriginalGriff [/edit]




Please help me to understand this. It may be easy, but I need an explanation.

Thanks
Fia

[edit]Underlining removed - it doesn''t work too well in a code block! - OriginalGriff[/edit]

推荐答案

它很简单:函数TreeNode.Nodes.Add(string)为您做到了:它知道您需要一个新节点(因为您给了它一个字符串,并告诉它将其添加到节点集合中),以便它创建并分配该字符串.
可能的添加功能列表@ MSDN [ ^ ]
TreeNodeCollection.Add(string)@ MSDNMSDN [
It''s quiet simple: the function TreeNode.Nodes.Add(string) does it for you: it knows you need a new node (because you have given it a string and told it to add it to a collection of nodes) so it creates it and assigns the string.
List of possible Add functions @ MSDN[^]
TreeNodeCollection.Add(string) @ MSDNMSDN[^]


If it makes you feel bad, you can create it yourself then hand the node to the Add function! :laugh:


这篇关于为什么我不必在行Dim子节点中将New用作TreeNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆