They do this in C# can't we do it in VB??

  • Thread starter Thread starter **Developer**
  • Start date Start date
D

**Developer**

They do this in C# can't we do it in VB??

Public Structure DevicePropMap

Public Shared id() As Integer = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 1026, 1027, 1028}


End Structure 'DevicePropMap
 
They do this in C# can't we do it in VB??

Public Structure DevicePropMap

Public Shared id() As Integer = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 1026, 1027, 1028}

End Structure 'DevicePropMap

Store 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1026, 1027, 1028 as a
string and parse/tokenize it?
 
**Developer** said:
They do this in C# can't we do it in VB??

Public Structure DevicePropMap

Public Shared id() As Integer = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 1026, 1027, 1028}


End Structure 'DevicePropMap

Mhm... The code semantically doesn't make sense.
 
Herfried K. Wagner said:
Mhm... The code semantically doesn't make sense.


It works with classes, why not with structures? It's just a member of the
type.


Armin
 
Hi,

Use a class instead of a structure

Public Class DevicePropMap

Public Shared id() As Integer = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 1026, 1027, 1028}


End Class 'DevicePropMap


Ken
 
Patrice said:
Which version ? AFAIK it should work in 2.0...

No, it doesn't work.

BTW: I would fire a programmer who designs a structure without instance
members...
 
Herfried K. Wagner said:
No, it doesn't work.

BTW: I would fire a programmer who designs a structure without
instance members...


:-) I guess, ***Developer*** posted only the interesting part of the
structure.


Armin
 
This is the result of converting a C# program using the converter that I got
from MS.

Actually the structure did have another part but it was basically the same
except that the type was string.

I'm beyond worrying about getting fired, but just in case, what the problem
that Herfried sees?

Thanks for the replies. I'll try using Class as that was the only suggestion
as how to make it work. Wish me luck.



Thanks
 
**Developer** said:
I'm beyond worrying about getting fired, but just in case, what the
problem that Herfried sees?


A structure (object) is a container for data. If there's no data, there's
no need for a structure. I only guess that this is the problem Herfried
sees - and I would agree. In opposite to classes, the singleton pattern
doesn't make sense with structures, in other words, if you don't intend to
create an instance, a class is the better (and only) way to implement it.

Or, in other words, a structure is a value type. A value type without a
value does not make sense.


Armin
 
Armin,
Or, in other words, a structure is a value type. A value type without a
value does not make sense.
As I was almost writing as well. However than it did look me to silly to
write, as you I assumed that it was partial code.

Cor
 
Armin,

Did you know that this way of coding is the way were Cobol is very much
based on. Therefore it is maybe not impossible that some developpers still
use (mimic) it. (Giving the same memory area different names and different
structures).

Cor
 
Cor Ligthert said:
Armin,

As I was almost writing as well. However than it did look me to
silly to write, as you I assumed that it was partial code.

Pardon?


Armin
 
Cor Ligthert said:
Armin,

Did you know that this way of coding is the way were Cobol is very
much based on.

No, I don't know Cobo.
Therefore it is maybe not impossible that some
developpers still use (mimic) it. (Giving the same memory area
different names and different structures).

Sorry Cor, I don't see the relation to the topic.


ARmin
 
Is the objection because there is only on variable.

Actually there were two variables.

One Integer array and one String array.

I think the struct mapped an id (integer) into a name (string).

The string array had the same format as the integer so I tried to simplify
the post.

Is the objection because there is only on variable and is that what you
meant by "singleton pattern"?


thanks


Armin Zingler said:
A structure (object) is a container for data. If there's no data, there's
no need for a structure.

Seems to me there is data - the array of integers. On the other hand putting
the array into a structure does not seem to add anything unless there are
other variables in the structure and you want to indentify them as being
related.

I think I'm missing something here.
 
**Developer** said:
Is the objection because there is only on variable.

Actually there were two variables.

One Integer array and one String array.

I think the struct mapped an id (integer) into a name (string).

The string array had the same format as the integer so I tried to
simplify the post.

Is the objection because there is only on variable and is that what
you meant by "singleton pattern"?


The point is that there was /no/ /instance/ variable. But, ask Herfried, it
was his statement.


Armin
 
Armin Zingler said:
A structure (object) is a container for data. If there's no data, there's
no need for a structure. I only guess that this is the problem Herfried
sees - and I would agree. In opposite to classes, the singleton pattern
doesn't make sense with structures, in other words, if you don't intend to
create an instance, a class is the better (and only) way to implement it.

Full ACK.
 
**Developer** said:
Is the objection because there is only on variable.

Actually there were two variables.

Two shared variables!
One Integer array and one String array.

I think the struct mapped an id (integer) into a name (string).

The string array had the same format as the integer so I tried to simplify
the post.

Is the objection because there is only on variable

The problem I see is that the variable is not an instance variable.
Instead, it's a shared variable. So it's irrelevant if you declare the
variable in a structure or a class. I suggest to post the complete code
listing and describe in more detail what you want to archieve. You may want
to include the full C# snippet too.
 
Armin Zingler said:
It works with classes, why not with structures? It's just a member of the
type.

Could you describe a scenario where the code above would semantically make
sense?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top