开发者

Dim and set the variable in 2 lines in vb.net

开发者 https://www.devze.com 2022-12-15 07:17 出处:网络
i have this line: Dim strings_extreme = 开发者_如何学JAVAinput.Split(\",\"c).Distinct().OrderBy(Function(s) s)

i have this line:

Dim strings_extreme = 开发者_如何学JAVAinput.Split(","c).Distinct().OrderBy(Function(s) s)

i need to Dim it in one line, and set it a value on another line

how do i do that?

would it just be Dim strings_extreme() ??

and then strings_extreme = input.split.... ?


Even though VB.net allows you not to specify the type, it's always more safe to specify it explicitly. Hence:

Dim strings_extreme as string()
strings_extreme = input... 


Just like this:

Dim strings_extreme
strings_extreme = input.Split(","c).Distinct().OrderBy(Function(s) s)

One note, though. I would turn on option strict. Its never a good idea to declare a variable without a type.

Dim strings_extreme As String()


Pretty close. Here it is:

Dim strings as string = "grape,apples,lime"
Dim strings_extreme
strings_extreme = Input.Split(strings,",").Distinct().OrderBy(Function(s) s)
for each e in strings_extreme
    e.tostring 'do something with this
next
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号