468,491 Members | 2,042 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

Anonymous array creation possible in VB.NET?

Hi,

Is it possible on VB.NET to create anonymous arrays, e.g. passing
arrays directly as a method-parameter instead of reference it from a
variable.

In C#, I can do this:
string s = "Blah blah, Aloha!";
string[] sArr = s.Split(new String[]{","});

In VB, do I really have to do it this way?
Dim s As String = "Blah blah, Aloha!"
Dim seperator() As Char = {CType(",", Char)}
Dim sArr() As String = s.Split(seperator)
Nov 20 '05 #1
6 7235
Hi,

Not really sure what u r asking.. but.. in VB y not code as follows?

Dim s As String = "Blah blah, Aloha!"
Dim sArr() As String = s.Split(CChar(","))

not sure how this is all that different from the C# version? appart from the
syntax obv.

Rigga.

"Anders Thomsen" <ju**@mexp.dk> wrote in message
news:5d**************************@posting.google.c om...
Hi,

Is it possible on VB.NET to create anonymous arrays, e.g. passing
arrays directly as a method-parameter instead of reference it from a
variable.

In C#, I can do this:
string s = "Blah blah, Aloha!";
string[] sArr = s.Split(new String[]{","});

In VB, do I really have to do it this way?
Dim s As String = "Blah blah, Aloha!"
Dim seperator() As Char = {CType(",", Char)}
Dim sArr() As String = s.Split(seperator)

Nov 20 '05 #2
Cor
Hi Anders,
In C#, I can do this:
string s = "Blah blah, Aloha!";
string[] sArr = s.Split(new String[]{","});

In VB, do I really have to do it this way?
Dim s As String = "Blah blah, Aloha!"
Dim seperator() As Char = {CType(",", Char)}
Dim sArr() As String = s.Split(seperator)


Most people do it like this,
Dim s As String = "Blah blah, Aloha!"
Dim sArr() As String = s.Split(",")

Maybe this is better, but I did never saw it done in this newsgroup and I
did not look to the intermidiate code for this.
Dim s As String = "Blah blah, Aloha!"
Dim sArr() As String = s.Split(","c)

I hope this helps?

Cor
Nov 20 '05 #3
"Anders Thomsen" <ju**@mexp.dk> schrieb

Is it possible on VB.NET to create anonymous arrays, e.g. passing
arrays directly as a method-parameter instead of reference it from
a variable.

In C#, I can do this:
string s = "Blah blah, Aloha!";
string[] sArr = s.Split(new String[]{","});

In VB, do I really have to do it this way?
Dim s As String = "Blah blah, Aloha!"
Dim seperator() As Char = {CType(",", Char)}
Dim sArr() As String = s.Split(seperator)

Dim sArr() As String = s.Split(new char(){","c})
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
Dim s As String = "Blah blah, Aloha!"
Dim sArr() As String = s.Split(New Char() {","c})

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
"Anders Thomsen" <ju**@mexp.dk> wrote in message
news:5d**************************@posting.google.c om...
Hi,

Is it possible on VB.NET to create anonymous arrays, e.g. passing
arrays directly as a method-parameter instead of reference it from a
variable.

In C#, I can do this:
string s = "Blah blah, Aloha!";
string[] sArr = s.Split(new String[]{","});

In VB, do I really have to do it this way?
Dim s As String = "Blah blah, Aloha!"
Dim seperator() As Char = {CType(",", Char)}
Dim sArr() As String = s.Split(seperator)

Nov 20 '05 #5
* ju**@mexp.dk (Anders Thomsen) scripsit:
Is it possible on VB.NET to create anonymous arrays, e.g. passing
arrays directly as a method-parameter instead of reference it from a
variable.


Yes:

\\\
....(..., New Char() {","c, ":"c, ...}, ...)
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
Anders,
In addition to the others comments (on how to actually create an "anonymous"
array) :

In C# you can do this:
string s = "Blah blah, Aloha!";
string[] sArr = s.Split(',');
In VB, you can also do this: Dim s As String = "Blah blah, Aloha!"
Dim sArr() As String = s.Split(","c)
Seeing as String.Split uses a ParamArray parameter, the compiler will
dynamically create an "anonymous" array for you, there is no real need to
explicitly create one (although one is supported if you already have one, or
you need to use String.ToCharArray).

Hope this helps
Jay

"Anders Thomsen" <ju**@mexp.dk> wrote in message
news:5d**************************@posting.google.c om... Hi,

Is it possible on VB.NET to create anonymous arrays, e.g. passing
arrays directly as a method-parameter instead of reference it from a
variable.

In C#, I can do this:
string s = "Blah blah, Aloha!";
string[] sArr = s.Split(new String[]{","});

In VB, do I really have to do it this way?
Dim s As String = "Blah blah, Aloha!"
Dim seperator() As Char = {CType(",", Char)}
Dim sArr() As String = s.Split(seperator)

Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

76 posts views Thread by Nick Coghlan | last post: by
5 posts views Thread by Stijn van Dongen | last post: by
1 post views Thread by Paul E Collins | last post: by
21 posts views Thread by yeti349 | last post: by
104 posts views Thread by Leszek | last post: by
20 posts views Thread by John Mark Howell | last post: by
60 posts views Thread by jacob navia | last post: by
5 posts views Thread by David Golightly | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.