Chris Cannon
Chris Cannon

Reputation: 1167

VB.NET to English - What is this line of code supposed to do?

Hi please could some interpret the following line of code into English?

"foo".TrimEnd(New Char(0  - 1) {})

I know what TrimEnd will do but not the Char bit.

Upvotes: 2

Views: 117

Answers (2)

Steven Liekens
Steven Liekens

Reputation: 14088

I think this is a NOOP because TrimEnd() is passed an empty array. This code will check if "o" (last character of "foo") is in the empty array, which it is not, and return "foo".

Upvotes: 2

Matt Wilko
Matt Wilko

Reputation: 27322

The code you posted is quite meaningless in the context posted so was this manipulated from some code you found or a made up example?

To answer your question:

  • TrimEnd removes characters from the end of a string
  • New Char(x) creates an array of characters to be removed, x specifies the size of the array
  • 0-1 specifies the upper bound of the array is -1 - this doesn't make much sense as the array starts at 0 and ends at -1
  • {} initialises the character array

Upvotes: 5

Related Questions