ref keyword bad communication between .net languages!
-
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 }
-
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 }
-
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 }
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 ) ; -
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 }
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);
-
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 ) ;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] -
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 ) ;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
-
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);
... 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(); }
-
... 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(); }
and which probably isn't what the code does anyway.