C
C#3y ago
surwren

Top-level statements in MSVS

Say you've created a new project with top-level statements in MSVS. Is it possible to change it to not use top level statements after the project has been created?
12 Replies
surwren
surwrenOP3y ago
Like say you leave "do not use top level statements" unticked in the above window during project creation How can this setting be reversed for the individual project?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Angius
Angius3y ago
Just add the boilerplate It's not like it's a whole different project type
surwren
surwrenOP3y ago
what about the other way around, where the setting is ticked and you want to avoid using the boilerplate after project creation?
Angius
Angius3y ago
Delete it
Klarth
Klarth3y ago
Just convert it by hand. It's a few LoC to add/delete. It's not a big deal.
Ainz
Ainz3y ago
it's just
public class Program
{
public static void Main() { // code go here }
}
public class Program
{
public static void Main() { // code go here }
}
but top level statements generates that boilerplate behind the scenes So Console.WriteLine("Hello World") in a Top Level Statement project gets built as
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World")
}
}
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World")
}
}
Klarth
Klarth3y ago
(Plus the namespace)
333fred
333fred3y ago
Press ctrl+. In the main method or on the top level statements There is a refactoring to convert to/from
Klarth
Klarth3y ago
Oh, nice.
surwren
surwrenOP3y ago
oh, this is native to msvs without resharper? hmm, ctrl + isn't doing anything
Pobiega
Pobiega3y ago
ctrl + . the dot matters

Did you find this page helpful?