Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 492
  • Last Modified:

C# what does "out" do here? internal static bool IsValidGUID(String s, out Guid value)

I know this function just verifies the content of string "s"... what does (and how does it work) "out Guid value" do here?

How is this function used?

internal static bool IsValidGUID(String s, out Guid value)
        {
            if (s == null || s.Length != 36)
            {
                value = Guid.Empty;
                return false;
            }
}
0
conrad2010
Asked:
conrad2010
  • 4
  • 4
1 Solution
 
p_davisCommented:
whatever is calling this method, im assuming, reacts when the guid value is empty after the return of the method
0
 
conrad2010Author Commented:
correct, just don't know what the "out" value does for the calling method
0
 
p_davisCommented:
can you show the method that  calls it?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
conrad2010Author Commented:
if (cGeneral.IsValidGUID(this.txtUID.Text, out newGuid))
        sDUID = this.txtUID.Text;
    else
        MessageBox.Show("Not a valid UID"); return;
0
 
conrad2010Author Commented:
with cGeneral.IsValidGUID being the function I posted originally
0
 
p_davisCommented:
no what is calling IsValidGUID.. on its own i can only guess what the out value is used for... whatever code passes the parameter to it is what i need to see
0
 
p_davisCommented:
and the code around it
0
 
käµfm³d 👽Commented:
When you use an out parameter you are allowing a method to manipulate the value a variable points to, and the caller of that function will see the change in the value. It's similar to what happens when you use reference parameters in C/C++. There is a similar keyword ref. The difference between the two is that when using out, the method must assign something to the variable before the method returns; with ref you may or may not assign something to the variable inside of the function, but within the caller of the function you must assign the variable prior to calling the function. In other words:

Given:

void SetString(out string s)
{
    s = "hello world!";
}

Open in new window


you could do the following:

string t;

SetString(out t);
Console.WriteLine(t);  // prints "hello world!"

Open in new window


Given:


void SetString(ref string s)
{
    s = "this is a test!";
}

Open in new window


you could do the following:

string t = "hello world!";

SetString(ref t);
Console.WriteLine(t);  // prints "this is a test!"

Open in new window

0
 
conrad2010Author Commented:
perfect answer and example!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now