PC Review


Reply
Thread Tools Rate Thread

Anonymous array creation possible in VB.NET?

 
 
Anders Thomsen
Guest
Posts: n/a
 
      20th Feb 2004
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)
 
Reply With Quote
 
 
 
 
Rigga
Guest
Posts: n/a
 
      20th Feb 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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)



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      20th Feb 2004
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


 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      20th Feb 2004
"Anders Thomsen" <(E-Mail Removed)> 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

 
Reply With Quote
 
Tom Spink
Guest
Posts: n/a
 
      20th Feb 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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)



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      20th Feb 2004
* (E-Mail 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, ...}, ...)
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      20th Feb 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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)



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perils and Merits of Anonymous classes? Anonymous Descendant class Siegfried Heintze Microsoft C# .NET 6 24th Feb 2008 03:50 AM
array creation (elementary question) gmb Microsoft VC .NET 2 4th Jun 2007 02:38 PM
zero element array creation Zytan Microsoft VB .NET 32 23rd Feb 2007 02:37 PM
RAID array creation =?Utf-8?B?dXAgYSBndW0gdHJlZQ==?= Windows XP Setup 6 8th May 2005 08:04 PM
Dynamic array creation =?Utf-8?B?QVJa?= Microsoft C# .NET 1 27th Feb 2004 05:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:57 AM.