break

Bug: as operator used with a reference type

I was trying to convert an object to a long in C# and tried it like this at first:

value = row.Cells[columnIndex].Tag as long;

I got the following error:

“The as operator must be used with a reference type (’long’ is a value type)”

The Solution

value = Convert.ToInt64(row.Cells[args.ColumnIndex].Tag);

Using Convert.ToInt64 will let you convert an object to a long.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

CAPTCHA Image
Reload Image