Anonymous array creation possible in VB.NET?

  • Thread starter Thread starter Anders Thomsen
  • Start date Start date
A

Anders Thomsen

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)
 
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.
 
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
 
Anders Thomsen said:
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
 
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
 
* (e-mail address removed) (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, ...}, ...)
///
 
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 said:
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)
 
Back
Top