|
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):
public void example(bool dummy)
{
myClass s;
if (dummy)
{
s = new myClass();
}
else
{
if (s==null)
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.
-- modified at 13:11 Monday 7th May, 2007
|
|
|
|
|
Hi Every one
while iam parsing one file my output file looks like this:
1aDOCSTART_3:
GENEVAVERSION:5.0
BILLSTYLE:2
BILLTYPE:1
BILLTEMPLATE:3
BILLSEQ:1
BILLVERSION:1
ACCCURRENCYCODE:GBP
BILLLANGID:1
BILLLANGNAME:English
BILLLANGLOCALE:en_GB
PAYMETHODID:4
FORMATREQ:TEST014/0001
COPYBILLNUM
BILLPURPOSE:1
BILLPURPOSENAME:Master
ADDRESS1:11
ADDRESS4:London
ZIPCODE:SW1V
COUNTRY:United
Start of BSTARTACCFADDR
ACCFADDR_1:11
ACCFADDR_2:London
ACCFADDR_3:SW1V
ACCFADDR_4:United
End of theBENDACCFADDR
CUSTOMERREF:TEST014
CUSTOMERTYPE:UK
ACCTAXSTATUS:Exclusive
INVOICINGCONAME:Genie
ACCOUNTNO:TEST014
DEPOSIT:000
CUSTCONTACTADDR1:11
CUSTCONTACTADDR4:London
CUSTCONTACTZIP:SW1V
CUSTCONTACTCOUNTRY:United
Start of BSTARTCUSTFADDR
CUSTFADDR_1:11
CUSTFADDR_2:London
CUSTFADDR_3:SW1V
CUSTFADDR_4:United
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.
Thanks&Regards
RENU
|
|
|
|
|
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.
|
|
|
|
|
Pete O'Hanlon wrote: Would you please stop posting the same question again and again? People have given you answers and suggestions to this question elsewhere.
Another one of those posters
|
|
|
|
|
DON345 wrote: i want to show this data as xml output
Means what ? Do you want to converet this file into xml ?
DON345 wrote: pls any one give me solution for this.
Yesturday we discuss it
DON345 wrote: 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!
|
|
|
|
|
Hi sandeep
sorry for disturbing you again and again
actually i want output as XML file having different elements with key value pair .
Thanks&Regards
RENU
|
|
|
|
|
OK But file is like this only key value seperated by : colon
need to develop logic its simple give some time
Thanks and Regards
Sandeep
If you want something you never had,
do something you have never done!
|
|
|
|
|
 Hi Renu here is your solution
<br />
protected void Button1_Click(object sender, EventArgs e)<br />
{<br />
StreamReader streamreader = File.OpenText(Server.MapPath("TextFile.txt"));<br />
XmlTextWriter xmlTextWriter= this.CreateXML();<br />
while (!streamreader.EndOfStream)<br />
{<br />
string line = streamreader.ReadLine();<br />
<br />
string[] values = line.Split(':');<br />
if(values.Length>1)<br />
writeElement(xmlTextWriter, values[0], values[1]);<br />
}<br />
this.EndXml(xmlTextWriter);<br />
xmlTextWriter.Close();<br />
}<br />
<br />
public XmlTextWriter CreateXML()<br />
{<br />
XmlTextWriter xTextWriter = new XmlTextWriter(Server.MapPath("Ouput.xml"), System.Text.Encoding.UTF8);<br />
xTextWriter.WriteStartDocument();<br />
xTextWriter.WriteStartElement("RootElement");<br />
<br />
<br />
<br />
return xTextWriter;<br />
<br />
}<br />
<br />
public void EndXml(XmlTextWriter xmlTextWriter)<br />
{<br />
xmlTextWriter.WriteEndElement();<br />
xmlTextWriter.WriteEndDocument();<br />
<br />
}<br />
<br />
public void writeElement(XmlTextWriter xmlTextWriter, string key, string value)<br />
{<br />
xmlTextWriter.WriteStartElement("Field");<br />
xmlTextWriter.WriteAttributeString("Key", key);<br />
xmlTextWriter.WriteAttributeString("Value", value);<br />
xmlTextWriter.WriteEndElement();<br />
<br />
<br />
}<br />
Expecting positive reply from you
Thanks and Regards
Sandeep
If you want something you never had,
do something you have never done!
|
|
|
|
|
Dont you think you are spoon feeding Renu?
|
|
|
|
|
Hi Arti
I know its like that but i am here in CP to learn something. Renu wanted the solution from last 3 days i had given 2 days but Renu coudn't find the solution that's why i provided solution
Thanks and Regards
Sandeep
If you want something you never had,
do something you have never done!
|
|
|
|
|
Hi sandeep thank you for sending solution.can we show the xml output like
staring and ending tags of each line is key and in between start and elements attribute as value
Ex:<key>value
Thanks&Regards
RENU
|
|
|
|
|
HI RENU
i Helped you as you were not getting solution from couple of days. It does not mean that i will provide you solution according to your requirement. Please find solution on google.
DON345 wrote: can we show the xml output like
staring and ending tags of each line is key and in between start and elements attribute as value
Ex:value
Yes you can do that just look at xmltext writer instead of providing Field as element name provide name you want
Thanks and Regards
Sandeep
If you want something you never had,
do something you have never done!
|
|
|
|
|
Hello...
I have a little problem with KeyDown event.
I'm using a Form with 1 TextBox.
If the textbox is focused, then event textbox_KeyDown will be called.
If the form is focused, then event form_KeyDown will be called.
What I want is:
If the textbox is focused, the event form_KeyDown must be called.
And idea how to do that ?
Thanks...
|
|
|
|
|
Have a look at Form.keypreview property 
|
|
|
|
|
Thanks.... It's so easy. Never used it before...
|
|
|
|
|
I've got a dataset that is populated by a 1000+ char SQL query, the amount of columns can be anything from 1 to 500. The columns has different headings.
I want to make a Report of this dataset, but it has to happen dynamically, each time the report will be different.
Is this possible ?
Thanks
|
|
|
|
|
Hi,
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.
vinay
|
|
|
|
|
i want to explorer Folder Option, Map Network Drive,Disconnect Network Drive, i use following code but not works?
System.Diagnostics.Process.Start("explorer.exe", "Map Network Drive");
Sanjit.rajbanshi@wlinktech.com
|
|
|
|
|
You can use command "net.exe" from windows.
To connect :
net use h: \\MYNOTEBOOK\C$
To disconnect :
net use h: /DISCONNECT /YES
Use Process.Start to run that command.
|
|
|
|
|
Hello, I have a couple of doubts about sockets.
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.
Regards,
Diego F.
|
|
|
|
|
First one:
"To determine the maximum number of connections you can specify, retrieve the MaxConnections value"[^]
Second one:
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))
{
}
Hope this helps
|
|
|
|
|
Thank you. That's what I needed.
Regards,
Diego F.
|
|
|
|
|
Hi all,
how can i convert an array of bytes into an array of string in classic VB?
How can i use Peek and Poke in Classic VB?
Thanks in advance....
|
|
|
|
|
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
|
|
|
|
|