Vb.net指针 [英] Vb.net Pointers

查看:315
本文介绍了Vb.net指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

vb.net中最类似于​​指针的东西是什么,就像C poinetrs一样?

What is the most similar thing in vb.net to a pointer, meaning like C poinetrs?

我在一个类中有一个TreeView.我需要公开一些可以被外部对象修改的特定节点(或叶子).

I have a TreeView within a class. I need to expose some specific nodes (or leaves) that can be modified by external objects.

推荐答案

Nathan W已经建议

Nathan W has already suggested the IntPtr structure which can represent a pointer or handle, however, whilst this structure is part and parcel of the .NET framework, .NET really doesn't have pointers per-say, and certainly not like C pointers.

这主要是因为.NET Framework是一个托管"平台,而内存是由CLR管理,分配,分配和释放的,而开发人员无需您担心(即无需malloc命令!​​),这主要是因为由于这种内存管理,您实际上并没有访问直接内存地址的权限.

This is primarily because the .NET Framework is a "managed" platform and memory is managed, assigned, allocated and deallocated by the CLR without you, the developer, having to worry about it (i.e. no malloc commands!) It's mostly because of this memory management that you don't really have access to direct memory addresses.

.a.net框架中可以被视为指针"(但实际上不是一个指针)的最接近的东西是委托.您可以将委托视为函数指针",但是,从严格意义上讲,它并不是真正的指针. 委托为调用函数添加类型安全性,从而允许代码调用"委托实例,以确保它使用正确的参数调用正确的方法.这与传统"指针不同,因为它们不是类型安全的,仅引用内存地址.

The closest thing within the .NET Framework that can be thought of as a "pointer" (but really isn't one) is the delegate. You can think of a delegate as a "function pointer", however, it's not really a pointer in the strictest sense. Delegates add type-safety to calling functions, allowing code that "invokes" a delegate instance to ensure that it is calling the correct method with the correct parameters. This is unlike "traditional" pointers as they are not type-safe, and merely reference a memory address.

.NET Framework中的任何地方都有代表,每当您使用

Delegates are everywhere in the .NET Framework, and whenever you use an event, or respond to an event, you're using delegates.

如果要使用C#而不是VB.NET,则可以编写标记为"指针 ,就像C一样,它们仍然有一些限制(例如指向的内存地址中的内容).

If you want to use C# rather than VB.NET, you can write code that is marked as "unsafe". This allows code within the unsafe block to run outside of the protection of the CLR. This, in turn, allows usage of "real" pointers, just like C, however, they still do have some limitations (such as what can be at the memory address that is pointed to).

这篇关于Vb.net指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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