结构体 ? [英] Structure ?

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

问题描述

我希望能够创建一个像我在VB6中那样的结构,它具有

变量


名称为字符串* 10

年龄为字符串* 3


表示字符串的大小。我可以在VB.net中以某种方式执行此操作吗?


我正在使用< StructLayoutArribute()和< MarshalAs()属性,但是

我真的不想将这些结构暴露给COM。我只想在VB.net程序集中使用




帮助!


JerryM

I want to be able to create a structure like I did in VB6, that have
variables

Name As String * 10
Age As String * 3

for the size of the strings. Can I do this some way in VB.net?

I''m playing with <StructLayoutArribute()and <MarshalAs()attributes, but
I''m not really wanting to expose these structrues to COM. I only want to use
them inside VB.net assemblies.

Help!

JerryM

推荐答案

" JerryWEC" < Je ****** @ newsgroups.nospamschrieb:
"JerryWEC" <Je******@newsgroups.nospamschrieb:

>我希望能够创建一个像我在VB6中那样的结构,它具有
变量


名称为字符串* 10

年龄为字符串* 3


的大小为字符串。我可以在VB.net中以某种方式做到这一点吗?
>I want to be able to create a structure like I did in VB6, that have
variables

Name As String * 10
Age As String * 3

for the size of the strings. Can I do this some way in VB.net?



此语法不再受支持。您可以使用

''VBFixedStringAttribute''属性来模仿它。但是,如果您将

程序集从VB6转换为VB.NET,我会重新考虑设计。你可以实现

''Name''和''Age''作为属性并将字符串填充到所需的长度

属性''''Set' '访问者。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps .org />

VB< URL:http://dotnet.mvps.org/dotnet/faqs/>

This syntax is not supported any more. You can mimick it using the
''VBFixedStringAttribute'' attribute. However, if you are converting the
assembly from VB6 to VB.NET, I''d rethink the design. You could implement
''Name'' and ''Age'' as properties and pad the string to the desired length in
the property''s ''Set'' accessor.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


2月16日,Jerry有人在这个

新闻组中提出了同样的问题。它是由''Rick Knospler'发布的&主题是''VB6

转换。需要帮助了解如何实现固定长度的字符串

数组..''


在这篇文章中你将得到你的答案


-

新手编码器

(这只是一个名字)
On the 16th Feb. Jerry someone asked the same sort of question in this
newsgroup. It was posted by ''Rick Knospler'' & the subject was ''VB6
Conversion. Need help understanding how to implement fixed length string
arrays..''

In this post you will have your answer

--
Newbie Coder
(It''s just a name)


Herfried,这是一个好主意......这是新代码,我希望有一些方法来模拟固定大小的字符串的旧方法。好像

新的Structure对象是矫枉过正的,应该有这个固定的字符串

内置的功能。


我''我仍然认为一个结构仍然比一个类快,因为它是存储在堆栈中的



TIA! JerryM
Herfried, this is a good idea... It is new code and I was hoping there was
a way to simulate the old way of doing strings for fixed size. Seems like
the new Structure object is overkill and should have had this fixed string
capability built in.

I''m still thinking a structure is still faster than a class since it''s
stored on the stack?

TIA! JerryM


这篇关于结构体 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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