Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Although, that's just one of many waysone of many ways to convert types in VB.NET.

Although, that's just one of many ways to convert types in VB.NET.

Although, that's just one of many ways to convert types in VB.NET.

deleted 12 characters in body
Source Link
Mathieu Guindon
  • 75.1k
  • 18
  • 191
  • 463

Lastly, idiomatic .net code will always have Option Explicit and Option Strict turned on... and you can reduce the verbosity of declarations by enabling Option Infer, so the compiler will automatically infer the correct type, so instead of this:

Dim foo As String = "something"

You can have that:

Dim foo = "something"

And foo is known at compile time (read: it's not a dynamic/runtime thing) to be a String.

Dim readResult As String() = File.ReadAllLines(inputFile)
Dim multipliedResults = From line In readResults
                        Select MultiplyEvenNumbers(Convert.ToInt32(line))

Lastly, idiomatic .net code will always have Option Explicit and Option Strict turned on.

Dim readResult As String() = File.ReadAllLines(inputFile)
Dim multipliedResults = From line In readResults
                        Select MultiplyEvenNumbers(Convert.ToInt32(line))

Lastly, idiomatic .net code will always have Option Explicit and Option Strict turned on... and you can reduce the verbosity of declarations by enabling Option Infer, so the compiler will automatically infer the correct type, so instead of this:

Dim foo As String = "something"

You can have that:

Dim foo = "something"

And foo is known at compile time (read: it's not a dynamic/runtime thing) to be a String.

Dim readResult = File.ReadAllLines(inputFile)
Dim multipliedResults = From line In readResults
                        Select MultiplyEvenNumbers(Convert.ToInt32(line))
added 893 characters in body
Source Link
Mathieu Guindon
  • 75.1k
  • 18
  • 191
  • 463

The CInt conversion function is also VB6-ish; in .NET you convert things, so instead of this:

CInt(readResult(i))

You would have that:

Convert.ToInt32(readResult(i))

Although, that's just one of many ways to convert types in VB.NET.

Lastly, idiomatic .net code will always have Option Explicit and Option Strict turned on.


What about LINQ?

As mentioned above, an array is an object. But it's not just any object - it implements an interface called IEnumerable, which means the LINQ extension methods can be used to iterate it, instead of an explicit For loop:

Dim readResult As String() = File.ReadAllLines(inputFile)
Dim multipliedResults = From line In readResults
                        Select MultiplyEvenNumbers(Convert.ToInt32(line))

But you'll probably want to learn a bit about closures and delegates before diving into this.

Lastly, idiomatic .net code will always have Option Explicit and Option Strict turned on.

The CInt conversion function is also VB6-ish; in .NET you convert things, so instead of this:

CInt(readResult(i))

You would have that:

Convert.ToInt32(readResult(i))

Although, that's just one of many ways to convert types in VB.NET.

Lastly, idiomatic .net code will always have Option Explicit and Option Strict turned on.


What about LINQ?

As mentioned above, an array is an object. But it's not just any object - it implements an interface called IEnumerable, which means the LINQ extension methods can be used to iterate it, instead of an explicit For loop:

Dim readResult As String() = File.ReadAllLines(inputFile)
Dim multipliedResults = From line In readResults
                        Select MultiplyEvenNumbers(Convert.ToInt32(line))

But you'll probably want to learn a bit about closures and delegates before diving into this.

Source Link
Mathieu Guindon
  • 75.1k
  • 18
  • 191
  • 463
Loading