My guess is that the C# compile knows that the if( true ) block will ALWAYS be executed and optimizes the if statement out. The result is that lenum = b.GetEnumerator() and lenum = c.GetEnumerator() are in the same scope.
Roger Stewart "I Owe, I Owe, it's off to work I go..."
The scopes of the two lenum variables overlap whereas those of the j variables do not. Read section 5.1.7 of the C# language specification.
Within the scope of a local variable, it is a compile-time error to refer to the local variable in a textual position that precedes its variable-declarator.
The lifetime of a local variable is the portion of program execution during which storage is guaranteed to be reserved for it. This lifetime extends from entry into the block, for-statement, switch-statement, or using-statement with which it is associated, until execution of that block, for-statement, switch-statement, or using-statement ends in any way.
These two statements together seem to indicate that the compiler is doing what it is suppose to. I wonder why the scope of a variable starts at the entry point of the block and not at the declaration point? Afterall, if you can't reference the variable in a textual position preceding the declaration then why not define its scope in the same manner? I'm sure there's a good answer. I just don't know what it is
leppie wrote: So C is not decent. Get a life or go back to whatever decent language you were using previously.
you would think a made i made a comment about your mother.
PS: did you even read my reply?
i did read your reply but you didn't explain the problem you just posted a work around.
PSSS: You are infact constructing your IEnumerator loop incorrectly. Here is the proper way:
incorrectly ? there is very little difference between the two and in my opinion the while loop is more readably, you don't have an empty statement as in your for loop.
what's the deal anyways. i make a couple of comments about the quirks in the language( every language has them ) and you go off on me like i declare C# as the worst language in the world and every programmer who uses is stupid.
now if i have offended anyone, i apologize. but you should remember its just another programming language. i don't think knights running around defending its honour are necessary.
I think you may have misunderstood what the point of the original post was. It was a question about how C# handles scoping. It is a very legitimate and intelligent question. The author was not looking for a work-around.
You could try using a compiler that doesn't punish good programmers for using perfectly legitimate code. Technically, there is no conflict so long as the outer scope lenum comes after the inner scope one. MS's csc and Mono's mcs both use this buggy scoping, however DotGNU Portable.NET's cscc allows this code (as well it should) since there is no conflict. It does reject code where the outer scope variable is declared before the inner scope variable, however (since in that case there is an actual conflict).
Here's the deal: I have created an XSD file that relates back to an XML data file. The XML data is EMPTY (no data), only the XML Header, DataSet name and reference to the XSD file comprise the contents of the XML (see below):
I load this XML file into a DataSet object using ReadXML() with the ReadSchema parm. While the XML data file is empty, this read statement succeeds just fine; expected this, it's all good.
Now, I want to add a 'record' into the XML file, so I need to create a new DataTable, but I want to use the schema that's already defined in the XSD for my table (makes sense). In my schema (XSD) file, this record is defined as MyDataRecord (if I view the Schema in designer, I can see the datastructure just fine).
Becase the XML file is empty, doing something like:
DataTable dt = MyDataSet.Tables["MyDataRecord"];
only returns NULL
I thought, perhaps, I could do the following:
DataTable dt = MyDataSet.Tables.Add();
and it would be "smart enough" to create a DataTable object using the schema datastructure, but it does not ...
I need to know how to create a DataTable object of type "MyDataRecord " so I have the complete data structure ...
There has GOT to be a simple way to do this, someone please enlighten me.
If you want to peek under the hood, maybe taking a look to .cs file generated by your .xsd may shed some light on the issue.
On the other hand, if you want to test the FillSchema solution, use a SqlDataAdapter, I gave you the wrong link
I checked the CS files in the generated code section, but I'll be #%&* if I can figure out what the differences were/are, between the generated code and what I had done programmically ... obviously there's something because it works now.
Thank you for the information and taking the time to respond.
OK, Is there anyone out there who has any idea of how to do this??? I have asked this question on multiple boards and multiple times. Research has lead me to only knowing that the constructor and destructor messages are communicated with the IMessage interface, but I have no clue on how to implement this. PLEASE, someone help!!!!!
I guess that this idea is something that hasn't been approached or not by anyone here. Thank you if you tried to research the issue, but I am not going to move on to a new approach since I have searched in vain for this answer.
Last Visit: 31-Dec-99 18:00 Last Update: 25-Sep-23 18:52