Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 550307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:16:28+00:00 2026-05-13T11:16:28+00:00

When in C# we have the out and ref parameter options, in VB there

  • 0

When in C# we have the out and ref parameter options, in VB there is a only one: ByRef.

Now, little ‘problem’ when trying to ‘eliminate’ the compiler warning saying that test was not initialized before passing as argument:

Dim test As MyParsableClass ' = Nothing  need imperatively?? '
' some code ... '
MyParsableClass.TryParse("value", test) ' warning on "test" here

the class brief declaration:

Class MyParsableClass

  Public Shared Function TryParse(ByVal value As String, _
    ByRef myParsableClass As MyParsableClass) As Boolean
    myParsableClass = Nothing
    If True Then
      ' parse code OK'
      myParsableClass = New MyParsableClass()
      Return True
    Else
      ' parse code NOK '
      ' myParsableClass remains Nothing '
      Return False
    End If

  End Function

End Class

maybe a solution was to declare

...Optional ByRef myParsableClass As MyParsableClass = Nothing)

but I can’t set this parameter as optional one. What will happen if I’ll miss it?

PS. (edit)

In the real project, my “parsable” class is MyHour with Hour and Minute properties. I wrote already the Parse(value as String) with a FormatException, but I think the code could be more clear, compact and quick when I will not use try catch blocks…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:16:29+00:00Added an answer on May 13, 2026 at 11:16 am

    I do not believe it’s possible to prevent this warning, without an explicit assignment.

    Different languages have different features/facilities – if they didn’t, there’d only be one programming language 🙂 In this case, yes, VB doesn’t pretend that there are two types of ref parameters, as C# does – so far as the CLR is concerned, “out” doesn’t exist.

    And I’m not sure what peSHIr is talking about – TryParse was added to later releases of the BCL for precisely the situation where a parse is as likely to fail as to succeed – so you can take a faulting path without requiring an exception to be thrown.

    Edit

    To add – the reason you don’t get a warning for many of the built in types for which a TryParse exists (e.g. Int32) is because they’re Structs/Value types, and hence always have a value. If your class is simple enough, would it be logical for it to be a Structure instead?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For ex. i have c# COM object with such function: int GetString([In, Out, MarshalAs(UnmanagedType.LPStr)]ref
I have checked out now a local working copy of a codebase that lives
When a method is defined with an out parameter, why do I have to
I have a stored procedure in Oracle that returns result set(s) via OUT parameter(s)
The problem is this: I want a generic function that has an out-parameter of
Problem I'm trying to figure this out for a while to no avail -
I have a function that takes a ref parameter and would like to use
I have tested out hundreds of different codes, either they work and screw something
I have been out of touch with Algorithms for a while and have start
I have commented out the hi Fold … line in my current vim-colorscheme (xoria256

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.