Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Desktop Developer

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

Search

XML Feeds

Google Ads

Tags: byval

comments
Rate Post:
submit to reddit Digg!FacebookDotnetkicks

I use C# to test my VB.Net assemblies. So today I got this little errormessage when doing this.

Here is the VB.Net method.

  1. ''' <summary>
  2. Public Sub SetFiberGroup(ByRef FiberGroup As FiberGroup)
  3.   _FiberGroup = FiberGroup
  4. End Sub

I don't use ByRef all that often but this time it was needed.

And normally you would call this like this in VB.Net.

  1. dim _FiberGroup as new FiberGroup
  2. _obj.SetFiberGroup(_FiberGroup)

Or something like that. No different then setting a ByVal parameter.

So I would expect C# to act the same. But it doesn't.

C# needs the ref keyword. like this

  1. var _FiberGroup = new FiberGroup();
  2. _obj.SetFiberGroup(ref _FiberGroup);

If you don't use the ref keyword then you need to get this little gem of an error.

Argument is 'value' while parameter is declared as 'ref'

So the solution is simple and logical. But I just wrote this in case anybody else bumps into this because Google doesn't seem to find that specific errormessage. Perhaps Yahoo will or Microsoft search but who uses those anymore.

About the Author

User bio imageChristiaan is a forensic technician who programs on the side, although my function description says that I do IT-things for 90% of the time . I'm an avid VB.NET fan and I use lots of the ALT.Net techniques, like unit-testing, nhibernate, logging, IoC, ...
Social SitingsTwitterLinkedInHomePageLTD RSS Feed
999 views
byref, byval, c#, vb.net
submit to reddit Digg!FacebookDotnetkicks

Comments and Feedback