A function with a Bitmap

  • Thread starter Thread starter RicercatoreSbadato
  • Start date Start date
R

RicercatoreSbadato

What's happen exactly when I pass a Bitmap to a function in this way:

text_localization(EMP1);
public Bitmap text_localization( Bitmap EMP1 ) {}
??

It's the same thing to do this?

text_localization(ref EMP1);
public Bitmap text_localization( ref Bitmap EMP1 ) {}
 
When the ref keyword is present, you can change the reference passed to the
function.

Consider this sample :

void fct1()
{
ClassX obj1 = null;
Class obj2 = null;
fct(obj1, obj2);

// obj1 == null
// obj2 != null
}

void fct2(ClassX o1, ref ClassX o2)
{
if (o1 == null)
o1 = new ClassX();
if (o2 == null)
o2 = new ClassX();
}

Fabien
 
ok, but my question was on the Bitmap Class. What I pass when I do so:

text_localization(EMP1);
public Bitmap text_localization( Bitmap EMP1 ) {}

??
 
I'm a bit confused and perhaps I don't understand exactly what's your
problem.

Since Bitmap is a class, and thus a reference type, you pass the reference
to the instance when simply passing it as parameter without the ref keyword.
If the question was "Is there a new instance of Bitmap created ?", the
answer is clearly "no".

Hope this helps.

Fabien
 
Hi,

It's a subtle differece , for one of the best explanation aroudn read this :
http://www.yoda.arachsys.com/csharp/parameters.html

in short the difference is that when use the "ref" you can change to what
instance the variable EMP1 refers to.

and in both cases you can change the instance reference by EMP1.


read the article, it's crystal clear there.


cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top