The error you are getting is simply the compiler warning you that you are using a variable that may not be explicitly initialized during runtime depending which path the execution flow takes.
In your case, you are using an uninitialised variable named s. The compiler is simply detecting that the execution might reach the catch and finally blocks with s never being explicitly initialized in your code and will therefore warn you because it's not sure if you know what you're doing (in your code this would happen if your class constructor throws an exception).
On the other hand, if you explicitly initialize the variable s to null, which makes no difference at runtime to what you originally coded, the compiler understands that you know what you are doing and that you have factored in the possibility of s being null if the catch and finally blocks are ever executed.
Please note that this is not something specific to try catch-blocks and constructors. You would get the same error in the following code (the code does not make much sense at all but its a valid example):
publicvoid example(bool dummy)
s = new myClass();
//do somethingelse//do something else
Hope this clears it up a little for you.
P.D. About the default constructor, C# does not work the same as C++. Having a default constructor will not make your variable s use it when its defined:
myClass s; //this will not call the default constructor as in C++. C# initializes objects to null.
Please note that the compiler error is not really necessary as the s variable is truely null even if not explicitly initialized and will therefore not cause unexpected behaviour reading uninitialised memory, etc. Its more an aid and a reminder to the coder that might be overlooking a possible execution path where the variable may not have the expected value. This becomes evident if instead of using your class you try your same code with int s; You will still get exactly the same error even though s is by default initialized to 0 and has a perfectly valid value.
Hi Every one
while iam parsing one file my output file looks like this:
Start of BSTARTACCFADDR
End of theBENDACCFADDR
Start of BSTARTCUSTFADDR
End of theBENDCUSTFADDR
i want to show this data as xml output.pls any one give me solution for this.
it is more helpful for me.
Would you please stop posting the same question again and again? People have given you answers and suggestions to this question elsewhere. If you have a problem with the answer, then it is only polite to respond to them.
Posting this question again and again looks like you are spamming the boards and will not actually prompt anyone to help you.
Deja View - the feeling that you've seen this post before.
Means what ? Do you want to converet this file into xml ?
pls any one give me solution for this.
Yesturday we discuss it
it is more helpful for me.
Actually you don't know whay you have to do.
Its difficult in first attempt but you should try once again
Reply what you want only out put key values or XML file having different elements with key value pair
Thanks and Regards Sandeep
If you want something you never had,
do something you have never done!
i have a requirement like to generate dynamic drodownlists based on the levels which r prasent in the levels table.i am successfully implemented dynamic controls.when ever we select the first dropdownlist based on the than value the corresponding data will be filled in the second dropdown list...like that remaing dropdownlists are filled.......when i am selecting the values in dropdown list the page is postback to server at that time entire page is refreshing im trying to avoid that one ........
please anyone kindly help me.if u think the question is incomplete, please let me know that.
First one. When I use Listen method, which is the maximum value I can put to the parameter. Can I just use the integer maxvalue?
Second one. I have a while loop to receive data from a remote host. If the host is down, how can I control that? What is the condition to put in the loop? I tried Socket.IsBound and Socket.IsConnected.
The Connected[^] property gives you the status of the socket at the last Send/Receive operation executed. You can use the return of the Poll method combined with other Properties of the socket to determine if the socket is down. Check here[^] for a table of input parameters and corresponding return values. A solution that's worked for me in the past was something like this:
if (socket.Poll(0, SelectMode.SelectRead) && (socket.Available == 0))
// the socket is down
Are you asking classic VB question in C# forum? Unusual way to commit suicide...
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe