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 possible100 Replies
install the SDK, that gets you the compiler and toolchain
$vscode
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.pngMicrosoft
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.
C# pretty much only has a single compiler, and that's the compiler that comes with the .NET SDK, linked above
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
Are you familiar at all with Java?
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
imagine Java, but the language and tooling aren't freeze dried dog vomit
oh!
lol okay
C# just looks really interesting to write in
its used in so many things
like FPS unlockers,
viruses, web even
etc.
You can think of .NET as the ecosystem (eg. tooling, compilers, languages) that surrounds C#.
C# comes with libraries?
don't write viruses, you'll be banned from this server
like community libraries?
yeah
oh i know
any virusware by me is simply for demonstration to test on my VMs lol
NuGet Gallery | Home
The NuGet Gallery is the central package repository for NuGet, the package manager for .NET.
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
C/C++ do
conan & vcpkg
ohhhh
i see
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
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
Python and Lua also have libraries, ex. Numpy
yea
lua is an extension language so
u have to install luvit or luarocks
for community works
(like actual requirable packages)
got it
just run?
looks like the installer
yeah run that
coolio
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
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
what else is there to the toolchain ?
wdym?
dotnet
is pretty much all you need for most thingsohh i sde
see
is nuget an extra installable ?
like with rust you can install uhh cargo or whatever idk
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 testsohh so nuget isbuilt in
yep
radical
let me try it
one sec
im gonna learn C# by writing some bot code
There is a separate CLI for Nuget, although afaik that's only relevant for publishing packages
Check out $helloworld if you need an introduction
Written interactive course https://learn.microsoft.com/en-us/users/dotnet/collections/yz26f8y64n7k07
Videos https://dotnet.microsoft.com/learn/videos
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?
yeah sure
dotnet
essentially has the same usage as cargo
or npm
or like
node
+ npm
okay thats easy to understand
good
what do i run to start a new project?
dotnet new
?Yup, that will show you the list of templates you can create
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
Well, you'll look at the description
hmm alright
You can start with
dotnet new console
That's just a regular console appyayyy
awesome
btw, you can just write
Console.WriteLine("Hi!");
if you want to skip the class and Main
stuffohhh
whats the point of a namespace then?
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
ohhh so
what if i just want one class?
Then you don't need a namespace, although it's kinda good practice to use one regardless (usually just the name of your app)
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?
You just type its name
i mean
for requiring
i figured it would be that way though
thank you
but yea how would i require it?
What do you mean "require"?
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.using
oh
let me try
did it !
=Dusing
does not mean what you are used to from JS
Separate files are not separate scripts that need to be cross-linkedi see
so all classes unless specified in a namespace are globally referencable ?
(unless its private)
Barring other visibility things like private or internal, yes
so what else is globally referencable
?
any variable scenarios?
There are no such things as global variables in C#
i see
Everything goes in a type
so only classes are referencable across files?
No. You can reference things off of classes
You could say
MyClass.MyStaticMethod()
, for exampleyea
like i did with
Hi
or
myInstanceOfMyClass.MyInstanceMethod()
well what i mean is
i can use classes across files, but what else can i use
(without stating it with
using
)Nothing
ah i see
Everything is in a class
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];
Namespaces and files have no relation
Many people choose to organize their files in a fashion that is related to the namespace
can namespaces be used with
using
even if theyre in the same dir?
or if theyre in different ones?I think you're still trying to relate this to files and
require
Throw it all awayyea im just trying to understand
Namespaces are a virtual "file-like" structure
i see
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;
alright that makes sense
This can even happen in the same file
Because you can have multiple namespaces in a single file
(but generally don't do that)
to me right now, namespaces seem like @thinker227 said
just folders for classes
or whatever theyre used for
but folders regardless
mm so
in that, how would you access
InA
They are, but they're virtual folders. They have nothing to do with where your actual files are located
using A;
underneath the namespace?
ofc
files and such just seem to be preferencetechnically yeah
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 rarerohhhokay
got it