You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the following example. As the comments describe, attempting to declare a field of type B.BStruct fails (Type could not be found), but the local variable b compiles successfully.
namespaceA{namespaceB{publicstructBStruct{}}publicstructAStruct{// This works!publicA.B.BStructbStructWithSurroundingNamespace;// This doesn't work!publicB.BStructbStructWithoutSurroundingNamespace;publicvoidFunc(){// ...but this *does* work!letb=B.BStruct();}}}
Here's a slightly modified example with a Main function. This program compiles and runs successfully, printing 123 to the console.
Here's where things get weird. I've isolated the Main function below. First, changing the b declaration to include the scope keyword fails compilation:
publicstaticvoidMain(){// Note the scope keyword that was previously absent.letb=scopeB.BStruct();let buffer =newString();Console.WriteLine(b.myInt);Console.ReadLine(buffer);deletebuffer;}
Compilation also fails when declaring b's type explicitly:
publicstaticvoidMain(){// In this case, adding the scope keyword changes nothing, i.e. compilation still fails.B.BStructb=.();let buffer =newString();Console.WriteLine(b.myInt);Console.ReadLine(buffer);deletebuffer;}
Given these examples, it's clear that, under the current implementation, the second example (the one with a Main function that runs successfully) is the odd man out.
Additional context: I stumbled onto this scenario when attempting to declare B.BStruct inside a function within namespace A. My assumption was that, within a particular namespace, I could implicitly access child namespace. In other words, inside Main (which lives inside namespace A), I would expect let b = scope B.BStruct(); to work, since namespace B is conceptually a "sibling" of the function.
To verify my expectation, I wrote a quick C# program, shown below. This function compiles and runs successfully.
namespaceA{namespaceB{publicstructBStruct{publicintmyInt;publicBStruct(){myInt=123;}}}publicstaticclassProgram{publicstaticvoidMain(){// This works!varb=newB.BStruct();Console.WriteLine(b.myInt);Console.ReadLine();}}}
The text was updated successfully, but these errors were encountered:
Consider the following example. As the comments describe, attempting to declare a field of type
B.BStruct
fails (Type could not be found
), but the local variableb
compiles successfully.Here's a slightly modified example with a
Main
function. This program compiles and runs successfully, printing123
to the console.Here's where things get weird. I've isolated the
Main
function below. First, changing theb
declaration to include thescope
keyword fails compilation:Compilation also fails when declaring
b
's type explicitly:Given these examples, it's clear that, under the current implementation, the second example (the one with a
Main
function that runs successfully) is the odd man out.Additional context: I stumbled onto this scenario when attempting to declare
B.BStruct
inside a function withinnamespace A
. My assumption was that, within a particular namespace, I could implicitly access child namespace. In other words, insideMain
(which lives insidenamespace A
), I would expectlet b = scope B.BStruct();
to work, sincenamespace B
is conceptually a "sibling" of the function.To verify my expectation, I wrote a quick C# program, shown below. This function compiles and runs successfully.
The text was updated successfully, but these errors were encountered: