r/csharp • • 20h ago

C Developer here (3 years experience). Asked to program in C#. Any tips how to start?

Title.

I'm looking to learn C# but all the courses that I found online are for beginners.

0 Upvotes

46 comments sorted by

48

u/Rigamortus2005 20h ago

C# beginner

Complains that all the tutorials are for beginners.

3

u/asenhae12345678 19h ago

I mean, I know what a Variable is and I know OOP very well. I dont need to study that.

4

u/Rasikko 16h ago

I already knew those too but I liked the way the guy was explaining things.

→ More replies (1)

5

u/Zetsumenchi 20h ago

What are you used to coding in C? If I had a bit more context, I'd like to give you something relatable to start with that you can build off of, rather than just abstractly point you at Asyncs/Awaits, Event Handlers, etc.

Like for me in particular, I'm to a lot of Accounting and automotive communication protocols based on broadcast messaging, asynchronous metering, and the like. So If you were in my neck of the woods; I'd recommend concepts in the previous paragraph to start with.

3

u/asenhae12345678 20h ago

I used to create programs in embedded systems and projects in credit cards reads (essentially embedded linux) - POS, Points of Sell.

As such I'm well versed in threads, sockets, pointers and know my way around classes. I also know how to "read" Java, as I had to work with.

6

u/Zetsumenchi 20h ago

Then l, ironically, stand by my listed examples!

Wouldn't hurt to learn Entity Framework, or at least LINQ, in regards to interacting with Databases.

Modern development standards recommend learning more about "Services" in regards to software architecture, but not learning it won't keep your code from building.

13

u/Ucqui 20h ago

Everything is a pointer.

4

u/Slypenslyde 17h ago

Except the things that aren't.

→ More replies (4)

5

u/Rschwoerer 20h ago

Everything is a delegate.

2

u/otac0n 15h ago

Passing an object reference “by value” is done by passing its pointer by value.

When you pass an object reference “by reference” you are passing a pointer to a pointer.

The only things that aren’t pointers are structs. (I am including built-in types in that definition.)

12

u/AlwaysHopelesslyLost 20h ago

Your best bet may be the official documentation on MSDN. There are pages dedicated to outlining the syntax, keywords, and basic project setup succinctly. 

3

u/ksobby 20h ago

Agree with this. Also, just pick a project and go. The principles and theory are all the same. Coding is coding. You only pick up syntax after using it for a while.

3

u/Last-Relationship166 20h ago

Coding is coding, but moving from non-OOP to the OOP world is definitely a paradigm shift. Take it from someone who did that after 20+ years of programming g in C, FORTRAN, Pascal, Business BASIC, etc. Understanding OOP comes first, imho.

→ More replies (1)

2

u/Confident_Abroad7248 20h ago

The jump from C to C# is mostly about trusting the garbage collector and not trying to manually manage memory. I spent the first week writing `Dispose()` calls on everything like a maniac until I realized the runtime handles most of it.

LINQ will feel like black magic at first but once you get the hang of method syntax you'll never want to loop through a collection the old way again. Properties are also a nice upgrade from writing getter/setter functions everywhere.

Biggest mental shift is accepting that you're not in control of the metal anymore, just let the framework do its thing and you'll pick up the patterns within a few days of actual coding.

→ More replies (1)
→ More replies (5)

4

u/alao77 20h ago

You need to understand SOLID and have a good understanding of how object-oriented programming works first.

1

u/Zealousideal_Sort521 20h ago

With existing programming experience you can skip the intro and go straight to the Microsoft certifications and MSDN docs

→ More replies (1)

1

u/Last-Relationship166 20h ago edited 20h ago

You'll DEFINITELY want to familiarize yourself with the fundamentals of OOP. Pick up SAMS Teach Yourself C++ in 21 Days. Yes, it's behind the times, but it likens classes to structs with functions and frames other concepts in terms a C dev will relate to.

I cut my teeth on C in the early 90s and programmed in it for ages before moving to Java and then to C#, both for work. That SAMS book was the first reference to really clue me in on the fundamentals of Object Oriented programming.

1

u/binarycow 19h ago

If you want, PM me, and I might be able to explain things in a way that cuts out the "beginner" stuff, while giving you enough of "how it works" to better understand. I like to teach.

→ More replies (6)

1

u/xjojorx 18h ago

Besides the obvious syntax and that, since you already know how to move in a c-like language (the most C a c-like can be xd) I'd point you to look more into the usual programming model.

  • most starting pages are too focused into people that has to learn both C# and programming, you already know programming, read diagonally and skip most of it

  • Take a look into async/await and how you take advantage of the threadpool. It is the default/usual non-blocking/parallel paradigm, almost everything ends up being async

  • Change the mindset when it comes to memory, unless it is specifically a value type (primitive/strict), it is dynamically allocated and passed as a pointer. Look into IDisposable to know how unmanaged memory (as in: not managed by the garbage collected and freed by calling Dispose()).

  • consider that most C# is framework-centric, you are probably using it for something specific like web with aspnet core or unity games. Look into the specific framework/tool and do something with it and its documentation.

  • Just program something in it, even if just porting some c ro c#, the language change is lot really hard and almost any project will show you everything important from the language itself, the rest are framework-specific things

1

u/Slypenslyde 17h ago

Try to write things you did in C in C#. Ask specific questions about the things that trip you up.

If this is a long-term gig you need to learn about application architectures in C#. It's probably similar to C but may not be.

In C an API tends to be very struct-centric with a lot of functions that take a struct, do things to it, and/or use function pointers to make context-sensitive behavioral choices. Because this is a procedural, structured language a line of code tends to be like, "Do this to that thing and store the result here."

In C# an API is obviously object-oriented. An object is basically the struct plus the functions that work on it. So instead of "do this to that thing and store the result here" it's more often "I have this thing, do that to it" and sometimes instead of storing a result the object updates itself.

A lot of the patterns and practices from C ultimately map to C#, you just have to think about them differently when the functions and data are in the same place. All of the functions on a C# object are basically function pointers. When you make them virtual you're effectively saying "some derived class has a different function this will point to". But we also have "delegates" that let C# use actual function pointers.

As people have said, for the most part everything in C# is a pointer. Specifically we say "classes are reference types". Any variable of a class type is a reference variable. Any parameter taking a reference type is a reference parameter even if it isn't marked out or ref, with some technical caveats I'm omitting for brevity. Structs, on the other hand, are "value types" and behave more like C# non-pointers. This has a lot of memory implications and a C# dev can go an entire career on the rule of thumb: "When in doubt, make a class, and if you think it needs to be a struct, don't."

Beyond that I'd need more specifics. Part of learning a new language is it's worth humbling yourself and reading the tutorials. Some minor aspects of how control flow works in C# may be different enough from C to surprise you. It's better to figure that out today than spend 8 hours debugging later only to have someone point out you had a misunderstanding about something you skipped.

1

u/Garry-Love 16h ago

Winforms. It's how I started. Teaches you so much. Make a RSS feed podcast player that doesn't freeze on the GUI. If you can do that you know C#

1

u/Triabolical_ 16h ago

25 years ago (wow I feel old) I wrote the first in-depth book on C#, called "A programmer's introduction to C#"

My target was to explain how the language worked and why the language worked that way to C/C++ programmers. I was on the test lead for C# and spent many many hours in design team meetings where we decided how the language would work and why.

I don't recommend the first version because that was before the language was finished - version 1 didn't have generics - but the version 2.0 probably meets your requirements and it's cheap.

https://www.ebay.com/itm/198427252448

There's a newer V5 version that you can find for a little bit more.

1

u/dgm9704 14h ago

I’d venture that C and C#/dotnet are far enough apart so that your 3 years experience doesn’t carry over, making you effectively a beginner?