|
Hey everyone,
I've been diving into C# .NET recently and I couldn't help but notice some similarities with C programming. I'm curious about how much C programming principles influence C# .NET and how understanding C might help in mastering C#.
Key Points of Discussion:
Syntax and Basic Constructs:
C# shares many basic syntax elements with C, such as data types (int, char, float), control structures (if, for, while), and operators (+, -, *, /). How much does familiarity with these elements in C help when learning C#?
Memory Management:
C provides manual memory management using malloc and free, whereas C# handles memory through garbage collection. How does this difference impact the way we write and optimize code in C# compared to C?
Pointers and References:
While C heavily relies on pointers, C# abstracts memory management but still allows the use of pointers in an unsafe context. How relevant are C pointers when dealing with C# programming, especially in performance-critical applications?
Object-Oriented Programming:
C# is inherently object-oriented, unlike C. For those coming from a C background, how challenging is it to grasp the object-oriented concepts in C#? How can C principles aid in understanding these concepts?
Platform Independence:
C# through .NET Core aims to be platform-independent, much like C programs can be compiled on various platforms. What are the key differences in achieving platform independence between the two languages?
Use Cases and Applications:
C is often used for system-level programming and embedded systems, while C# is popular for web applications, desktop applications, and game development using Unity. How do these different use cases affect the choice of language and the transition from C to C#?
Your Experiences and Insights:
I’d love to hear from those of you who have experience in both C and C#. How did your knowledge of C help (or not help) you when learning C#? Are there specific areas where you felt a strong correlation or significant differences? Any tips for someone coming from a C background and looking to excel in C# .NET?
Looking forward to an engaging discussion!
Cheers,
Tejaswini
modified 31 mins ago.
|
|
|
|
|
...this feels like a test. Are you trying to get us to do your homework?
|
|
|
|
|
Perhaps surprisingly, C# and C share very little, other than some superficial similarities in syntax - and it's not until you understand both languages pretty well that you can appreciate (or even notice!) many of them!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
C# is part of the C like programming language family. (like C++, rust, ...)
They all share some syntactic similarities, but they quickly diverge into their own specific language.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
My opinion is that if you learn any programming language at all then you have learned 50% of all of them, arbitrary percentages notwithstanding. It's more "true" if we subdivide into things like functional vs OOP languages.
A loop is a loop, the core of just about every data structure tend be an array, a hashmap is a hashmap, race conditions, resource contention, thread safety, cyclomatic complexity, atomicity... All these concepts and a great many more are going to exist no matter what language you are working in.
This is part of the argument I think I have read before which posits that multilingual people tend to pick up programming a bit easier and already have the neurons knocking around upstairs in much an order suitable. This makes sense because programming is just the language we use to command machines.
There are/can be vast differences and the nuances do often matter. But the concepts - those bits that help you understand what matters and what does not? These are very universal.
|
|
|
|
|
Once you've learned one of the "curly brace languages", you've learned nearly all of them because you've learned the concepts behind them. All the same concepts apply to all languages. After you learn the concepts, it's just a matter of semantics in describing what you want the code to do.
|
|
|
|
|
Seems like you asked ChatGPT to create questions for you to ask here nice try. NEXT !!!
Caveat Emptor.
"Progress doesn't come from early risers – progress is made by lazy men looking for easier ways to do things." Lazarus Long
|
|
|
|
|
I don't think of them as much the same. They're both C family so the syntax is similar, but that's about where the similarities end.
The datatypes for example, appear the same but they are not. A C int is not equivalent to a C# concept of an int as C's word size is not fixed, but varies by machine. Floats and doubles are the same but that probably has as much to do with IEEE as anything.
Using pointers in C# raises the question of why not use C? More importantly, the unsafe context only works on code that is fully trusted, greatly limiting where and how it can be deployed. There's almost nothing you can do with unsafe that you can't do with the marshalling infrastructure. Finally, using pointers often harms GC performance because you have to pin memory addresses so they don't get relocated during a collection.
I don't know how hard it is to grasp OOP. I picked it up in the 1980s. It has been too long, but I don't remember it being especially difficult - particularly once you understand how C++ implements classes and that you can make virtually the same constructs in C, just more verbose.
C is cross compatible source code. C# is cross compatible binary code. C# requires a VM. C does not. C runs in far more places - places where C# will never run.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
Agree, except: C# requires a VM ... unless I misunderstood your statement
|
|
|
|
|
C# requires a VM. C does not.
I wrote that. I can defend it. The CLI is a virtual machine. Its instruction set is IL. Its runtimes are the CLR.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
But it will compile finally to the target machine native processor code
|
|
|
|
|
It's JIT compiled, which is an implementation detail of the VM, similar to javascript on a modern browser.
Furthermore, setting aside that, it still cannot manage memory without the CLI, even compiled to native code. It requires the virtual machine in order to do basic operations. That machine is not simply part of the run time library like C's heap stuff. It's garbage collected - a process.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
As OriginalGriff said the similarities between C and C# are pretty superficial. It's really just syntactical: braces for for blocks, semicolon statement separators, simple data types (int, char, float, etc.) and simple control statements (if, for, while, etc.), other things I can't think of right now.
C, C#, C++, Java, Go, Rust, Kotlin, others? All share much of this same basic syntax. It makes it somewhat simpler to learn or move between them.
My understanding is C# was Microsoft's answer to Java after losing it's court case against Oracle over the future of Java in the late 1990's.
|
|
|
|
|
As an old member here answered once...
Do not forget that my compiler compiled your compiler.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
A proper C compiler is implemented in C and compiles itself.
|
|
|
|
|
Has anyone noticed that when you get a vscode update, the release notes never call out the bugs that were fixed.
<snark>I bet it's because the list is so large that it would cause the release notes file to be larger than the max possible size...</snark>
<moresnark>How do they exppect us to be able to reliably develop our own buggy code if the tools they provide us are so buggy?</moresnark>
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
They expect us to be dazzled by the list of wonderful enhancements.
|
|
|
|
|
The latest whiz-bang is "text to speech".
Speak this MS - "I don't give a f*ck about text to speech.".
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Still better than the vast majority of "app store"-type release notes, which are invariably some variation of:
Release Notes: Bug fixes and performance improvements.
Sometimes with slightly more embellishment, but it usually translates to the same meaningless BS.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Or so short, because they didn't fix a damn thing.
If you can't find time to do it right the first time, how are you going to find time to do it again?
PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com
Latest Article: EventAggregator
|
|
|
|
|
Microsoft fix bugs?
When did they start doing that?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: Microsoft fix bugs?
No need when you can just enhance over them.
User: "Microsoft, have you fixed the xyz bug?"
MS: "Did you see the list of 300 enhancements including new fonts and icons?"
User: "Oh, look at all the shiny."
|
|
|
|
|
Misc bugfixes...
You can always check the list of issues closed for that release on GitHub
|
|
|
|
|
I tried VSCode and never found it a good solution for my needs. As a pure editor it's worse than VisualStudio + VisualAssistX, for C# or Windows C/C++ code it's worse...
I found it acceptable for Python but I wrote 100 lines of Python in my whole life so take it with a deposit of salt.
GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
The shortest horror story: On Error Resume Next
|
|
|
|
|
I've never felt the need to use VS Code rather than Visual Studio.
In a closed society where everybody's guilty, the only crime is getting caught. In a world of thieves, the only final sin is stupidity. - Hunter S Thompson - RIP
|
|
|
|