473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

function object

hi All

in vb function can pass object, like

Function test(ByVal txt As TextBox)

txt.Text = "text"

End Function

if i want to do this function using C#.
how can i do?
thanks.
Nov 17 '05 #1
3 2157
In .Net, EVERYTHING is an object. So, of course, you can pass one as a
parameter. However, if you want to make a change to the object passed, you
should pass it by Reference. In .Net, you would do it like so:

Function test(ByRef txt As TextBox)

txt.Text = "text"

End Function

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big things are made up of
lots of little things.

"yysiow" <yy****@ytlesolutions.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
hi All

in vb function can pass object, like

Function test(ByVal txt As TextBox)

txt.Text = "text"

End Function

if i want to do this function using C#.
how can i do?
thanks.

Nov 17 '05 #2
PJ
That's unnecesssary and incorrect. The byval and byref refer to the pointer
of the object, not the object itself. Attributes of the TextBox instance
would still be modified outside of the function they were modified in.

However, for value ( base ) types such as int32 you would need to pass it
byref if you want to modify the instance. There is rarely a need for that
as proper scoping eleminates this need.
"Kevin Spencer" <ke***@takempis.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
In .Net, EVERYTHING is an object. So, of course, you can pass one as a
parameter. However, if you want to make a change to the object passed, you
should pass it by Reference. In .Net, you would do it like so:

Function test(ByRef txt As TextBox)

txt.Text = "text"

End Function

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Big things are made up of
lots of little things.

"yysiow" <yy****@ytlesolutions.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
hi All

in vb function can pass object, like

Function test(ByVal txt As TextBox)

txt.Text = "text"

End Function

if i want to do this function using C#.
how can i do?
thanks.


Nov 17 '05 #3
True, but that sort of information goes over the heads of certain types of
developers, for example, VB developers that are migrating to VB.Net. As you
stated, the need is rare, but not non-existent. For example, when you pass
an object without passing it ByRef, you can not change the assignment of the
object variable, only its' properties. Understanding the difference between
reference types and value types is also a more advanced topic. So I
simplified it. Passing an object ByRef hurts nothing.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.

"PJ" <pj***@hotmail.com> wrote in message
news:eW**************@TK2MSFTNGP12.phx.gbl...
That's unnecesssary and incorrect. The byval and byref refer to the pointer of the object, not the object itself. Attributes of the TextBox instance
would still be modified outside of the function they were modified in.

However, for value ( base ) types such as int32 you would need to pass it
byref if you want to modify the instance. There is rarely a need for that
as proper scoping eleminates this need.
"Kevin Spencer" <ke***@takempis.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
In .Net, EVERYTHING is an object. So, of course, you can pass one as a
parameter. However, if you want to make a change to the object passed, you should pass it by Reference. In .Net, you would do it like so:

Function test(ByRef txt As TextBox)

txt.Text = "text"

End Function

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Big things are made up of
lots of little things.

"yysiow" <yy****@ytlesolutions.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
hi All

in vb function can pass object, like

Function test(ByVal txt As TextBox)

txt.Text = "text"

End Function

if i want to do this function using C#.
how can i do?
thanks.



Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.