Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C# C# Tutorials

Antero360

Software Developer
Staff Team
Security Analyst
Beginners:
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.

Intermediates/Advanced:
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.
 
What are the pros and cons of learning C# instead of another C / +

C# is a managed high-level language like Java, so it's not really comparable to C or C++ despite it's similar name.
Compared to Java it offers some interesting advantages like:

- Generics without type erasure

That's an important one for me.
Firstly it allows you to overload on a parameter being, for example, either List<string> or List<int>.
Other than that non-erased types also make something like new T() possible which helps writing more generic code.
Example:

C#:
// The "where" restricts T to types that provide
// a parameterless constructor, to prove to the C#
// compiler that "new T()" can work.
public T Make<T>() where T : new() {
    return new T();
}

- Language-integrated async/await for asynchronous programming

- Language-integrated events through event and delegate

- Safe pointers (ref, in, out)

- More control over data placement (struct is on the stack, class is on the heap)

- "Low level" access despite being a high-level language
C# allows you to dive deep and gives you access to raw pointers (fixed), manual memory allocations (stackalloc), and unsafe operations if you need them.

...and many other things that I probably forgot.

All in all C# is a pretty decent language, but it's large and requires some effort to fully master it.
It's worth it though, especially because we now have official cross-platform support through .NET Core.

If you want to start learning C#, a book I can recommend is Jon Skeet's "C# in Depth".
 
Last edited:
Thank you, I really like that you spent some time answering.
I honestly didn't know the differences between C# and the other Cs were as drastic. So it sounds like C# adds a lot of high level functionality for programmers to use, while also being a bit more forgiving and hiding some of the behind-the-scenes work. I did some extra googling & definitely have a better understanding thanks to that and your reply.

Do the other Cs support asynchronous methods/functions? If so, is it a lot harder to implement them?
Sounds like C# makes things easier, but still allows you to dig deep into the core code behind it, which suggests that C/C+/C++ have a lot of functionality, but they require a lot of work on the programming side. Is that correct?

Cheers :)
 
Do the other Cs support asynchronous methods/functions? If so, is it a lot harder to implement them?

C is a very small language. People jokingly refer to it as a "portable assembler".
The closest thing to async programming you can get there are OS threads through the APIs of your operating system (eg pthread on Linux).

C++ is more advanced than C and even has some threading abstractions since C++11. (std::thread)
However you won't find "async methods" here either.

That's because async methods are really not that easy to implement (especially not for heavily cross-platform and cross-architecture languages like C/C++).
Async methods, also known as "green threads" or "Fibers", are an implementation of "cooperative multitasking".
The usual thread that you've likely encountered before is called "preemptive multitasking".

Fibers are "cooperative" because they are managed by a scheduler in your language's runtime.
When you run a fiber, the scheduler tries to find an empty spot in it's thread pool and lets it work.
If your fiber blocks (for example through a sleep, device access, or whatever) it "yields".
That means the scheduler is told that the fiber won't be able to do any work until some condition happens,
and that it is now free to make room for other fibers on that native thread.

This means that you can cheaply run thousands of fibers on a pretty average machine,
while constructing an OS thread is usually rather expensive and limited to the number of CPU cores.

Back to your question: The closest thing we have to this right now in C++ is the Boost Fiber library.
You can check it out at https://github.com/boostorg/fiber and https://www.boost.org/doc/libs/1_70_0/libs/fiber/doc/html/index.html.
It's a good library without doubt and I've used it in a few projects so far, but all in all it requires writing way more code when compared to higher languages like C#.
 
C is known as the "portable assembler" due to its low-level classification, since it works closer to the actual memory than any of the other languages.
C++ is known as the intermediate language because it works with C and builds more functionality.
C# is known as a "high-level" language, just like Java.
 
Back
Top Bottom