Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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.


    yysiow Guest

  2. Similar Questions and Discussions

    1. onChanged function not working with Shared Object
      Hey guys, I'm trying to get my Shared Object script to flush() data when I use the onChanged function instead of a Save button b/c I'm creating a...
    2. [FMX]Problem with caling function in linked object
      I'm trying to achief the following: In my flash movie I load some MC during runtime. Everything is fine, the MC show themselves on the...
    3. New Function gives Object Expected Error
      Hello, This problem has been driving me nuts... I have a set of functions and code which work fine by itself and another function which works...
    4. object in a function!?
      I have one little issue here.... let say that I have a function , and in that function some object functions are used.... which is better ...
    5. Can you return a dictionary object from a function?
      "Mark Schupp" <mschupp@ielearning.com> wrote in message news:OwPxqtxPDHA.1748@TK2MSFTNGP11.phx.gbl... doh!
  3. #2

    Default Re: function object

    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
    [url]http://www.takempis.com[/url]
    Big things are made up of
    lots of little things.

    "yysiow" <yysiow@ytlesolutions.com> wrote in message
    news:%23DMHGcnSDHA.1552@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.
    >
    >

    Kevin Spencer Guest

  4. #3

    Default Re: function object

    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" <kevin@takempis.com> wrote in message
    news:%23yDT8FtSDHA.3796@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
    > [url]http://www.takempis.com[/url]
    > Big things are made up of
    > lots of little things.
    >
    > "yysiow" <yysiow@ytlesolutions.com> wrote in message
    > news:%23DMHGcnSDHA.1552@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.
    > >
    > >
    >
    >

    PJ Guest

  5. #4

    Default Re: function object

    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
    [url]http://www.takempis.com[/url]
    Complex things are made up of
    lots of simple things.

    "PJ" <pjwal@hotmail.com> wrote in message
    news:eWPHVF7XDHA.1004@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" <kevin@takempis.com> wrote in message
    > news:%23yDT8FtSDHA.3796@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
    > > [url]http://www.takempis.com[/url]
    > > Big things are made up of
    > > lots of little things.
    > >
    > > "yysiow" <yysiow@ytlesolutions.com> wrote in message
    > > news:%23DMHGcnSDHA.1552@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.
    > > >
    > > >
    > >
    > >
    >
    >

    Kevin Spencer Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139