James Wilson
James Wilson

Reputation: 5150

Error 4 'DateRange' is a 'variable' but is used like a 'method'

This code is being converted over from vb.net and I don't know vb.net very well so i am using the telerik online vb.net to c# converter.

I don't understand why this is giving me an error...

string[] DateRange = this.cboPayPeriods.SelectedItem.Text.ToString().Replace(" ", "").Split('-');

while (Convert.ToDateTime(DateRange(0)) <= Convert.ToDateTime(DateRange(1)))

It will not build and says

'DateRange' is a 'variable' but is used like a 'method'

Can someone please help?

Upvotes: 0

Views: 365

Answers (3)

Hogan
Hogan

Reputation: 70538

In C#, arrays are referenced with [ and ] not ( and ). Change it like this:

while (Convert.ToDateTime(DateRange[0]) <= Convert.ToDateTime(DateRange[1]))

BTW, this is the mistake everyone makes when going from VB to C#.

Upvotes: 2

codingbiz
codingbiz

Reputation: 26396

Try this

change DateRange(0) to DateRange[0]

Looks like you are using VB syntax instead of C#

Upvotes: 2

Tim Schmelter
Tim Schmelter

Reputation: 460288

DateRange is a Array, you access an array via indexer via brackets [] in C# instead of round brackets () in VB.NET.

So this should work:

while (Convert.ToDateTime(DateRange[0]) <= Convert.ToDateTime(DateRange[1]))

Upvotes: 1

Related Questions