C
C#2y ago
thieved

new to C#, looking for a compiler?

i'm coming from javascript and lua what's a good compiler for C#? i'm looking to write C# with Visual Studio Code if possible
100 Replies
jcotton42
jcotton422y ago
install the SDK, that gets you the compiler and toolchain $vscode
MODiX
MODiX2y ago
1) Install the C# extension 2) 2.a) DO NOT USE OPEN FILE 2.b) Always use Open Folder (from the File menu), and open the folder containing your sln file (or the folder containing the csproj if you have only one csproj) 3) To make the extension start and detect C#, either: 3.a) wait for the prompt that will appear on the bottom right of your screen that ask you if you want it to create some files, and say Yes 3.b) Command Palette (F1 or Ctrl+Shift+P) and type > .Net : Generate Assets for build and run 4) you should see a flame on the Status bar with the Omnisharp logo (see second attached screenshot) 5) it should load to finally say OmniSharp server is running (if not ask for help) https://media.discordapp.net/attachments/569261465463160900/1006652191689429022/unknown.png https://cdn.discordapp.com/attachments/569261465463160900/951015732769079336/unknown.png
jcotton42
jcotton422y ago
Microsoft
Download .NET (Linux, macOS, and Windows)
Free downloads for building and running .NET apps on Linux, macOS, and Windows. Runtimes, SDKs, and developer packs for .NET Framework, .NET, and ASP.NET.
Thinker
Thinker2y ago
C# pretty much only has a single compiler, and that's the compiler that comes with the .NET SDK, linked above
thieved
thievedOP2y ago
ohh i see im not familiar with these kinda concepts yet like .NET and stuff i come from languages where simplicity is a given lol
Thinker
Thinker2y ago
Are you familiar at all with Java?
thieved
thievedOP2y ago
i can write basic programs in it i wanna learn C# and become a more in-depth programmer so i can understand concepts like multi-threading, single-threading, etc. i understand them at a surface level
jcotton42
jcotton422y ago
imagine Java, but the language and tooling aren't freeze dried dog vomit
thieved
thievedOP2y ago
oh!
jcotton42
jcotton422y ago
when
thieved
thievedOP2y ago
lol okay C# just looks really interesting to write in its used in so many things like FPS unlockers, viruses, web even etc.
Thinker
Thinker2y ago
You can think of .NET as the ecosystem (eg. tooling, compilers, languages) that surrounds C#.
thieved
thievedOP2y ago
C# comes with libraries?
Thinker
Thinker2y ago
don't write viruses, you'll be banned from this server catsip
thieved
thievedOP2y ago
like community libraries?
Thinker
Thinker2y ago
yeah
thieved
thievedOP2y ago
oh i know any virusware by me is simply for demonstration to test on my VMs lol
Thinker
Thinker2y ago
Check out https://www.nuget.org where you'll find all the libraries under the sun
NuGet Gallery | Home
The NuGet Gallery is the central package repository for NuGet, the package manager for .NET.
thieved
thievedOP2y ago
im not a blackhat programmer i had a question so C# has a community library right but things like C and C++ dont? ive always wondered lol ive never looked
jcotton42
jcotton422y ago
C/C++ do conan & vcpkg
thieved
thievedOP2y ago
ohhhh i see
Thinker
Thinker2y ago
well "library" is an ambiguous term, usually it just refers to pieces of code written by others which you can use in your own code
thieved
thievedOP2y ago
yea well what i really mean is your code can be assisted by other people's code like NPM, etc. a global repository of tools
Thinker
Thinker2y ago
Python and Lua also have libraries, ex. Numpy
thieved
thievedOP2y ago
yea lua is an extension language so u have to install luvit or luarocks for community works (like actual requirable packages)
thieved
thievedOP2y ago
got it
thieved
thievedOP2y ago
just run?
Thinker
Thinker2y ago
looks like the installer yeah run that
thieved
thievedOP2y ago
coolio
Thinker
Thinker2y ago
Also, I hope you're familiar with using the console for stuff, because using VSCode means that you'll have to use the console for a lot of stuff
thieved
thievedOP2y ago
oh ofc im familiar with console commands windows or external lol i dont like visual studio because i dont feel like i have controlover my process visual studiocode is just an IDE really that consists of extensions
thieved
thievedOP2y ago
thieved
thievedOP2y ago
thieved
thievedOP2y ago
what else is there to the toolchain ?
Thinker
Thinker2y ago
wdym? dotnet is pretty much all you need for most things
thieved
thievedOP2y ago
ohh i sde see is nuget an extra installable ? like with rust you can install uhh cargo or whatever idk
Thinker
Thinker2y ago
dotnet build to build your projects dotnet run to run your projects dotnet publish to publish your projects dotnet add package to add Nuget packages dotnet test to run tests
thieved
thievedOP2y ago
ohh so nuget isbuilt in
Thinker
Thinker2y ago
yep
thieved
thievedOP2y ago
radical let me try it one sec im gonna learn C# by writing some bot code
Thinker
Thinker2y ago
There is a separate CLI for Nuget, although afaik that's only relevant for publishing packages Check out $helloworld if you need an introduction
thieved
thievedOP2y ago
sometimes i feel dumb because i dont know certain parts of tech-talk but theni realize i dont really need to if im solo programming lol ima try it out can i keep this open?
Thinker
Thinker2y ago
yeah sure
Aaron
Aaron2y ago
dotnet essentially has the same usage as cargo or npm
Thinker
Thinker2y ago
or like node + npm
thieved
thievedOP2y ago
okay thats easy to understand good what do i run to start a new project? dotnet new ?
333fred
333fred2y ago
Yup, that will show you the list of templates you can create
thieved
thievedOP2y ago
got it! how do i know what kinda template i want though? i mean i know i need a console one but in what case should i need the ohter stuff lol
333fred
333fred2y ago
Well, you'll look at the description
thieved
thievedOP2y ago
hmm alright
Thinker
Thinker2y ago
You can start with dotnet new console That's just a regular console app
thieved
thievedOP2y ago
yayyy
thieved
thievedOP2y ago
namespace Epic
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hi!");
}
}
}
namespace Epic
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hi!");
}
}
}
awesome
Thinker
Thinker2y ago
btw, you can just write Console.WriteLine("Hi!"); if you want to skip the class and Main stuff
thieved
thievedOP2y ago
ohhh whats the point of a namespace then?
Thinker
Thinker2y ago
namespaces are only really useful if you're dealing with multiple classes namespaces are like folders on your computer, they help you organize classes into categories
thieved
thievedOP2y ago
ohhh so what if i just want one class?
Thinker
Thinker2y ago
Then you don't need a namespace, although it's kinda good practice to use one regardless (usually just the name of your app)
thieved
thievedOP2y ago
oh i see sorry for asking all this i just know that it might not be easy to find specific thing slike this but if i wanted to require one class from a file without a namespace how would that work?
Thinker
Thinker2y ago
You just type its name
// File 'Foo.cs'
class Foo {}
// File 'Foo.cs'
class Foo {}
// File 'Program.cs'
Foo foo = new Foo();
// File 'Program.cs'
Foo foo = new Foo();
thieved
thievedOP2y ago
i mean for requiring i figured it would be that way though thank you but yea how would i require it?
333fred
333fred2y ago
What do you mean "require"?
Thinker
Thinker2y ago
You don't 'require' things in C# If Foo happens to be from another library, then you have to add a reference to that library, but otherwise you don't have to do anything C# operates on the existence of .csproj files, which act as the root of a single project. If you run dotnet new console -n "MyProject", it'll generate a MyProject.csproj in the root directory. All .cs files in the root directory or any sub-directories are part of the project, and all classes declared in those files can be used in any of the other files. So the classes are just 'required' automatically However, if you group your classes into namespaces (as you typically should), then you'll have to put using YourNamespace; at the top of your file(s) in order to use classes inside that namespace.
thieved
thievedOP2y ago
using oh let me try
namespace Epic
{
public class Program
{
public static void Main(string[] args)
{
Hi.Yell();
}
}
}
namespace Epic
{
public class Program
{
public static void Main(string[] args)
{
Hi.Yell();
}
}
}
public class Hi
{
public static void Yell()
{
Console.Write("HIIII!");
}
}
public class Hi
{
public static void Yell()
{
Console.Write("HIIII!");
}
}
did it ! =D
333fred
333fred2y ago
using does not mean what you are used to from JS Separate files are not separate scripts that need to be cross-linked
thieved
thievedOP2y ago
i see so all classes unless specified in a namespace are globally referencable ? (unless its private)
333fred
333fred2y ago
Barring other visibility things like private or internal, yes
thieved
thievedOP2y ago
so what else is globally referencable ? any variable scenarios?
333fred
333fred2y ago
There are no such things as global variables in C#
thieved
thievedOP2y ago
i see
333fred
333fred2y ago
Everything goes in a type
thieved
thievedOP2y ago
so only classes are referencable across files?
333fred
333fred2y ago
No. You can reference things off of classes You could say MyClass.MyStaticMethod(), for example
thieved
thievedOP2y ago
yea like i did with Hi
333fred
333fred2y ago
or myInstanceOfMyClass.MyInstanceMethod()
thieved
thievedOP2y ago
well what i mean is i can use classes across files, but what else can i use (without stating it with using)
333fred
333fred2y ago
Nothing
thieved
thievedOP2y ago
ah i see
333fred
333fred2y ago
Everything is in a class
thieved
thievedOP2y ago
i sorta understand so do you have to put namespaces in their own folders? or can you have them in the same dir and put using [Namespace];
333fred
333fred2y ago
Namespaces and files have no relation Many people choose to organize their files in a fashion that is related to the namespace
thieved
thievedOP2y ago
can namespaces be used with using even if theyre in the same dir? or if theyre in different ones?
333fred
333fred2y ago
I think you're still trying to relate this to files and require Throw it all away
thieved
thievedOP2y ago
yea im just trying to understand
333fred
333fred2y ago
Namespaces are a virtual "file-like" structure
thieved
thievedOP2y ago
i see
333fred
333fred2y ago
If you're not in a namespace, then you can't see anything in that namespace by default, and you need to bring that namespace into scope by specifying using Namespace;
thieved
thievedOP2y ago
alright that makes sense
333fred
333fred2y ago
This can even happen in the same file Because you can have multiple namespaces in a single file
Thinker
Thinker2y ago
(but generally don't do that)
thieved
thievedOP2y ago
to me right now, namespaces seem like @thinker227 said just folders for classes or whatever theyre used for but folders regardless
MODiX
MODiX2y ago
Orannis#3333
sharplab.io (click here)
namespace A {
class InA { }
}
namespace B {
class InB {
InA NotVisible;
}
}
namespace A {
class InA { }
}
namespace B {
class InB {
InA NotVisible;
}
}
React with ❌ to remove this embed.
thieved
thievedOP2y ago
mm so in that, how would you access InA
333fred
333fred2y ago
They are, but they're virtual folders. They have nothing to do with where your actual files are located
thieved
thievedOP2y ago
using A; underneath the namespace? ofc files and such just seem to be preference
Thinker
Thinker2y ago
technically yeah
333fred
333fred2y ago
You have 3 options: 1. using A; at the top of the file. (preferred) 2. using A; inside the namespace B { declaration. (You may see code like this, as something like 40% of of users do it this way) 3. Fully qualify InA, by saying A.InA where it's used 3 is sometimes used when you want to use a single type from a namespace and don't want to generally make the all the things in the namespace visible locally But it's rarer
thieved
thievedOP2y ago
ohhhokay
namespace A
{
public class B
{
public static void C()
{
Console.WriteLine("Yes!");
}
}
}
namespace A
{
public class B
{
public static void C()
{
Console.WriteLine("Yes!");
}
}
}
using A;

namespace Epic
{
public class Program
{
public static void Main(string[] args)
{
A.B.C();
}
}
}
using A;

namespace Epic
{
public class Program
{
public static void Main(string[] args)
{
A.B.C();
}
}
}
got it
thieved
thievedOP2y ago
Want results from more Discord servers?
Add your server