C
C#2y 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
surwren2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Angius
Angius2y ago
Just add the boilerplate It's not like it's a whole different project type
surwren
surwren2y ago
what about the other way around, where the setting is ticked and you want to avoid using the boilerplate after project creation?
Angius
Angius2y ago
Delete it
Klarth
Klarth2y ago
Just convert it by hand. It's a few LoC to add/delete. It's not a big deal.
Ainz
Ainz2y 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
Klarth2y ago
(Plus the namespace)
333fred
333fred2y ago
Press ctrl+. In the main method or on the top level statements There is a refactoring to convert to/from
Klarth
Klarth2y ago
Oh, nice.
surwren
surwren2y ago
oh, this is native to msvs without resharper? hmm, ctrl + isn't doing anything
Pobiega
Pobiega2y ago
ctrl + . the dot matters
Want results from more Discord servers?
Add your server
More Posts
how to format multiple conditions assignments in return statement [CLOSED] [Answered]Greetings, I was wondering, how could I properly format this piece of code. ```cs return res > PagEntity Framework One-To-One [Answered]Code at: https://paste.mod.gg/rccwzntafwoj/0 When attempting to change the database I'm getting: TDatabase - Relationship returns empty set even though records are present [Answered]I think I'm probably missing something stupid obvious... In my batch model, I have ```cs private reaSave storageFile to a folder on driveI have a storagefile ready to give to a control to crop an image the problem is that image crop wilDynamically load .dll into .NET 6 ProgramHi, I've a Blazor WebAssembly Hosted (.NET 6) web application. I've put some part of the applicationMove File To A Matching Type RefactoringWhen everything is top-level do you not need namespaces because everything is "top-level"? Thanks foClass making my program run as a background process after I close it [Answered]https://paste.myst.rs/7o8qz5vk After I close my program through RMB>Close window it continues runniHangfire - Unable to resolve services [Answered]Working with Hangfire. I have a plugin service which has an InitializeAsync method that looks like tASP.NET Website project without namespaces. Converting to ASP.NET Web application.Hi guys, I have a legacy ASP.NET Website project which I want to convert to ASP.NET Website applicatBest Way to Save Client_Secret and access_token?Hey i got now the Discord Login on my Tool Ready but now i need to Safe Data like the Access_token,