Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. ref keyword bad communication between .net languages!

ref keyword bad communication between .net languages!

Scheduled Pinned Locked Moved Clever Code
csharpbusinesshelp
8 Posts 7 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrcooll
    wrote on last edited by
    #1

    i have discover that if u have two different project in same solution first is Presentation tear in C# and the other is BLL 'Business logic layer' tear in Vb.net have by ref Form parameter, you cant call it form c# by sending this as a parameter! public sub SetFormPrivilage(by ref frm as Form) '' 'Some code goes here! '' End sub private SomeForm_load(object sender,EventArgs e) { SomeClassInOtherProjectObject Obj=new SomeClassInOtherProjectObject(); Obj.SetFormPrivilage(ref this);//Error you cant assign ref to this //or Obj.SetFormPrivilage(this);//Error SetFormPrivilage expect ref keyword }

    J P O 3 Replies Last reply
    0
    • M mrcooll

      i have discover that if u have two different project in same solution first is Presentation tear in C# and the other is BLL 'Business logic layer' tear in Vb.net have by ref Form parameter, you cant call it form c# by sending this as a parameter! public sub SetFormPrivilage(by ref frm as Form) '' 'Some code goes here! '' End sub private SomeForm_load(object sender,EventArgs e) { SomeClassInOtherProjectObject Obj=new SomeClassInOtherProjectObject(); Obj.SetFormPrivilage(ref this);//Error you cant assign ref to this //or Obj.SetFormPrivilage(this);//Error SetFormPrivilage expect ref keyword }

      J Offline
      J Offline
      jamie550
      wrote on last edited by
      #2

      Form blah = this; Obj.SetFormrivilage(ref blah); Of course, if blah changes, "this" will not. But that would be strange anyways This also happens in pure C#, iirc, as it should

      1 Reply Last reply
      0
      • M mrcooll

        i have discover that if u have two different project in same solution first is Presentation tear in C# and the other is BLL 'Business logic layer' tear in Vb.net have by ref Form parameter, you cant call it form c# by sending this as a parameter! public sub SetFormPrivilage(by ref frm as Form) '' 'Some code goes here! '' End sub private SomeForm_load(object sender,EventArgs e) { SomeClassInOtherProjectObject Obj=new SomeClassInOtherProjectObject(); Obj.SetFormPrivilage(ref this);//Error you cant assign ref to this //or Obj.SetFormPrivilage(this);//Error SetFormPrivilage expect ref keyword }

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        That's not a language problem, you're simply not allowed to pass this that way: " CS1605: Cannot pass '<this>' as a ref or out argument because it is read-only " And it's certainly not subtle. In your case you probably don't need to pass by reference anyway. Or you could do something like:

        object o = this ;
        Obj.SetFormPrivilage ( ref o ) ;

        CPalliniC P 2 Replies Last reply
        0
        • M mrcooll

          i have discover that if u have two different project in same solution first is Presentation tear in C# and the other is BLL 'Business logic layer' tear in Vb.net have by ref Form parameter, you cant call it form c# by sending this as a parameter! public sub SetFormPrivilage(by ref frm as Form) '' 'Some code goes here! '' End sub private SomeForm_load(object sender,EventArgs e) { SomeClassInOtherProjectObject Obj=new SomeClassInOtherProjectObject(); Obj.SetFormPrivilage(ref this);//Error you cant assign ref to this //or Obj.SetFormPrivilage(this);//Error SetFormPrivilage expect ref keyword }

          O Offline
          O Offline
          ohmikkie
          wrote on last edited by
          #4

          I think you've misunderstood reference types. One should not need to pass a from object "by ref". Effectively this would be the equivalent to passing a pointer to a pointer in C (**). Being that a Form is an object, you only need to pass its reference:- public sub SetFormPrivilage(frm as Form) '' 'Some code goes here! '' End sub private SomeForm_load(object sender,EventArgs e) { SomeClassInOtherProjectObject Obj=new SomeClassInOtherProjectObject(); Obj.SetFormPrivilage(this);

          J 1 Reply Last reply
          0
          • P PIEBALDconsult

            That's not a language problem, you're simply not allowed to pass this that way: " CS1605: Cannot pass '<this>' as a ref or out argument because it is read-only " And it's certainly not subtle. In your case you probably don't need to pass by reference anyway. Or you could do something like:

            object o = this ;
            Obj.SetFormPrivilage ( ref o ) ;

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            PIEBALDconsult wrote:

            And it's certainly not subtle.

            :-D

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            In testa che avete, signor di Ceprano?

            1 Reply Last reply
            0
            • P PIEBALDconsult

              That's not a language problem, you're simply not allowed to pass this that way: " CS1605: Cannot pass '<this>' as a ref or out argument because it is read-only " And it's certainly not subtle. In your case you probably don't need to pass by reference anyway. Or you could do something like:

              object o = this ;
              Obj.SetFormPrivilage ( ref o ) ;

              P Offline
              P Offline
              Paul Conrad
              wrote on last edited by
              #6

              PIEBALDconsult wrote:

              it's certainly not subtle.

              No kidding. I thought this was rather common knowledge.

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

              1 Reply Last reply
              0
              • O ohmikkie

                I think you've misunderstood reference types. One should not need to pass a from object "by ref". Effectively this would be the equivalent to passing a pointer to a pointer in C (**). Being that a Form is an object, you only need to pass its reference:- public sub SetFormPrivilage(frm as Form) '' 'Some code goes here! '' End sub private SomeForm_load(object sender,EventArgs e) { SomeClassInOtherProjectObject Obj=new SomeClassInOtherProjectObject(); Obj.SetFormPrivilage(this);

                J Offline
                J Offline
                johannesnestler
                wrote on last edited by
                #7

                ... true - except you want to reallocate the reference itself in the function... This is one of the few reasons I know why you'd pass a reference-type per reference. But this is no approach I'd recommend - it can lead to very nasty bugs! - But for shure all know that ;) void Reallocate(ref ReferenceType obj) { obj = new ReferenceType(); } this doesn't work: void Reallocate(ReferenceType obj) { obj = new ReferenceType(); }

                P 1 Reply Last reply
                0
                • J johannesnestler

                  ... true - except you want to reallocate the reference itself in the function... This is one of the few reasons I know why you'd pass a reference-type per reference. But this is no approach I'd recommend - it can lead to very nasty bugs! - But for shure all know that ;) void Reallocate(ref ReferenceType obj) { obj = new ReferenceType(); } this doesn't work: void Reallocate(ReferenceType obj) { obj = new ReferenceType(); }

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  and which probably isn't what the code does anyway.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups