Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have been using a guide to help me write a small c# based excel application and have come accross a line of code that I have no idea what it acctualy does. IF someone could give me a brief explanation that would be great.

object misValue = System.Reflection.Missing.Value;
xlWorkBook.Close(true,misValue,misValue);


I don't really understand how (what) misValue actually does.

Thanks in advance

Dan
Posted

In means this: http://msdn.microsoft.com/en-us/library/system.reflection.missing.aspx[^].

Missing represents a parameter which is used by default if default parameter feature is used. Default parameters were introduced in C# v.4, but the mechanism itself already existed before. If the parameter is omitted, it is equivalent to passing a default value of the parameters. However, through Reflection, this parameter is not known to the caller. What to do? This is no any special value like null. A default parameter is specified by the author of the method to be called. Through Reflection, System.Reflection.Missing.Value should be passed.

—SA
 
Share this answer
 
v3
Comments
DanHodgson88 11-Jul-11 4:30am    
cheers for that :)
Sergey Alexandrovich Kryukov 11-Jul-11 4:36am    
Thank you, Dan.
--SA
Uday P.Singh 11-Jul-11 4:38am    
correct answer my 5 too!!
Sergey Alexandrovich Kryukov 11-Jul-11 5:05am    
Thank you, Uday.
--SA
DanHodgson88 11-Jul-11 4:39am    
Thats great SA much Appreciated :) - Dan
I think this page in the MSDN will shed some light on it:

http://msdn.microsoft.com/en-us/library/system.reflection.missing.value.aspx[^]

Such questions can usually be answered quickly with the help of Google :)
 
Share this answer
 
Comments
DanHodgson88 11-Jul-11 4:32am    
cheers for that :) yeh you are right it was a bit of a "google" question. I had already looked at both your links and still struggled to understand what it does. msdn doesn't really explain it in "English" very well! Appreciate the reply though mate. I think I need to look at the constructor for xlWorkBook.Close for more info. :)
Sergey Alexandrovich Kryukov 11-Jul-11 4:36am    
Frankly, it's all right. From this MSDN page it is not immediately clear. I tried to explain things.
--SA
Sergey Alexandrovich Kryukov 11-Jul-11 4:35am    
I already answered a while ago.
Please see: I also added explanation.
--SA
[no name] 11-Jul-11 4:37am    
I have never worked with it, but from what I have seen 'Missing' a singleton class which contains information on missing parameters in method calls. That is possible since there may be parameters in method calls which have a default value. If you call the method and omit the params with default values, they are missing and have to be replaced by the default values.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900