473,406 Members | 2,954 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,406 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 2159
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.