Word Add-In: Passing Parameters by Reference?

P

Peter

Hello,

Thanks for reviewing my question. I have written a sample C# add-in for
Word and I am curious why (when calling a Word's own API) that I have to pass
optional parameters as a reference. (I cannot say this is the case for all
of them but it seems common.) I would think they would be by value so you
can pass them as null.

Word.ApplicationClass appWord = new Word.ApplicationClass();
object objTemplate = "";
object objNewTemplate = false;
object objDocType = Word.WdNewDocumentType.wdNewBlankDocument;
object objVisible = true;
appWord.Documents.Add(ref objTemplate,ref objNewTemplate,ref objDocType,ref
objVisible);

Thanks
Peter
 
J

Jonathan West

I believe the reason is that C# doesn't have the concept of passing named
parameters in the way that VBA and VB.NET do.

Therefore, optional parameters can only be identified by their position in
the parameter list. Therefore, you need to pass parameters in the list that
are earlier than the one that you actually want to pass.
 

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

Top