Click here to Skip to main content
15,884,892 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,
I have some confusion on the following code
try
{

}
catch (Exception ex)
            {
                con.Close();
                MessageBox.Show(ex.Message);
            }

If I replace the '.' with a comma
MessageBox.Show(ex.Message);
With
MessageBox.Show(ex,Message);

It shows different thing, can any one please define this?


Thanks & regards
Indrajit dasgupta

[edit]Code blocks added, general tidy up- OriginalGriff[/edit]
Posted
Updated 5-May-11 0:27am
v2

When you put a comma in the method definition, you get a list of parameters you can enter into that method.
This is part of intellisense in order to help the user choose the appropriate overloaded methods.

If you put a ".", you get a list of members that you can use for that object.
 
Share this answer
 
Comments
Hemant__Sharma 5-May-11 6:47am    
Right. My 5
Abhinav S 5-May-11 7:03am    
Thanks.
public static DialogResult Show(
	string text,
	string caption,
	MessageBoxButtons buttons,
	MessageBoxIcon icon,
	MessageBoxDefaultButton defaultButton,
	MessageBoxOptions options,
	string helpFilePath
)


these are MessageBox parameters.

when you call
MessageBox.Show(ex.Message);

Only string text is Displayed.

when you call
MessageBox.Show(ex,Message);


string text,
string caption are displayed
 
Share this answer
 
MessageBox has a number of overloads for the Show method:
By replacing the '.' with ',' you are trying to use an overload with two parameters.
The compiler will probably complain that it cannot cast an Exception to a IWin32Window
 
Share this answer
 
So the comma(,) is used to specify separate parameters, so with a dot you are calling

MessageBox.Show(String)


and with comma you are calling

MessageBox.Show(String, String) //or similar


the second of course will give you an error message of Message not defined (I assume) and that Show does not have an overload that takes 'Exception' as first paramater
 
Share this answer
 
v2
with
C++
MessageBox.Show(ex.Message);

u r using Message property of exception

with
C++
MessageBox.Show(ex,Message);

u r passing two parameters.
so both r different thing
 
Share this answer
 
In the first instance you are calling MessageBox.Show(String), the second shouldn't build.
 
Share this answer
 

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