|
-
Nov 19th, 2004, 07:07 AM
#1
ByRef or ByVal? [Resolved]
Last question for today.
VB Code:
static void RunApp(object state)
{
Application.Run((Form)state);
}
I am currently converting it to VB.NET, I'd like to know whether "state" is being passed ByRef or ByVal. Does C# have the concept of ByRef/ByVal?
Last edited by mendhak; Nov 25th, 2004 at 07:29 AM.
-
Nov 19th, 2004, 07:21 AM
#2
Hyperactive Member
I am not quite sure bout that but if I recall correctly,......
if you pass an object it will always be passed by refrence.
But yes you can also specify that using keywords ref (out) or val.
heres an example:
Code:
private void button2_Click(object sender, System.EventArgs e)
{
System.Xml.XmlDocument myDoc = new System.Xml.XmlDocument();
testFunction(myDoc);
textBox2.Text = myDoc.SelectSingleNode("//test").InnerText;
}
private void testFunction(System.Xml.XmlDocument myDoc)
{
myDoc.LoadXml("<test>value</test>");
}
Please do corrcet me if I am wrong!
Stephan
Last edited by Sgt-Peppa; Nov 19th, 2004 at 07:49 AM.
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Nov 19th, 2004, 07:27 AM
#3
Reference types (Forms, other complex objects) will always be ByRef. Value types (primatives, structs) will always be ByVal unless the ref modifier is used.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 19th, 2004, 07:35 AM
#4
OK, so what I understand is that it's the same deal as in VB.NET, except it's taboo to mention it in C#.
-
Nov 19th, 2004, 07:46 AM
#5
Yup
Burstable Bandwidth
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 19th, 2004, 09:43 AM
#6
Wont arrays also be essentially byref as well?
-
Nov 22nd, 2004, 07:39 AM
#7
That's what I assumed too.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|