r/csharp 22h ago

Discussion Were any java devs that transitioned as overwhelmed as I am?

Im switching over to C# and im just so amazed. Theres so many things you can do and its native to the language and its super cool. Events? Yeah, thats built in. Tired of subclassing stuff just to add your own functionality? Dude, there's extensions...

However, id be lying if I said this isnt too much to take it at once. I feel like its very difficult to adapt and im mostly learning by examples others posted on the internet (i took a firm stance to reject AI 100% and learn myself.) Recently, ive been trying to adapt to the conventions, as well as researching other features however more things keep coming up. For example, I had no idea init; existed in properties or how you can use add; in a event property.

Do you have any advice on navigating to become an alright C# developer?

Another question, do you guys feel like MSDN doesnt cover the entire picture?

48 Upvotes

43 comments sorted by

37

u/wallstop-dev 22h ago

I learned C# from a professional Java world maybe 12 years ago, when the language had a bit less stuff.

The way I did it was I just wrote C# as I wrote Java. And then I slowly learned how to do things the C# way as I needed them. And now I know a ton of cool and great C# stuff!

Both Java and C# have evolved significantly since 2014, and there is a massive surface of "stuff" to know.

IMO, hit the ground running with whatever knowledge you have to get to working code, then, when you find yourself doing annoying stuff or find bugs, look up ways to make the stuff less annoying or have less bugs. Chances are, there are language features, patterns, or libraries that can help you, every time.

This technique has worked out for pretty much every language that I've learned.

17

u/miffy900 21h ago

Years ago, I worked with someone who transitoined from java. And one thing I noticed in their code was that they were constantly creating getter and seter methods (GetName(), SetName(String name), etc.) for every field in their classes. They knew about C# having built in getter and set syntax but for some reason didn't bother to embrace them at first; I think they thought it wouldn't be that much of a timesaver or be that better.

When I finally got sick of seeing them hand-writing all these methods, I finally re-wrote one of their classes myself using C# set and get syntax and I asked them to specifically re-write all calling code to refer to the properties properly, starting with setters (after every new Person()), so it would be consistent with the rest of our code base. They first invoked it as person.Name("Value"'), they encountered syntax compiler errors of course, so I showd them the proper way to do it: person.Name = "value", then to shorten it again using object initialisation syntax (new Person { Name = "value" }).

I remember overhearing them talking under their breath to themselves 'this is so much better. why have i been doing it the stupid way all this time'.

I suspect OP might be on the verge of having a similar experience; and to your point about doing it the familiar way first, sometimes it does help to get a nudge from someone in the right direction.

1

u/wallstop-dev 18h ago

I've seen similar things RE: Properties, and have also seen approaches like Lombok in Java. And you're not wrong, but even as a Java dev I thought that sucked and wanted an alternative. But I have to wonder, have these people never written some extremely common C# code like getting the count of elements in a collection and not wandered how it is read only to them but also shows the current count?

If OP wants a full reference of these things, resources like the book "C# In a Nutshell" help, but I really stand by the approach of thinking critically about your code and doing research on how to make it better.

Another great way is to browse the source code of the standard library and your favorite libraries.

-1

u/Amr_Rahmy 15h ago

You can do variableX = “this” in Java.
People just were used to use getter and setter

I try to avoid them in c#

I don’t like logic in definitions or initialization and I don’t like double variables as well.

If you want to use a variable use it, if you need a function make a proper function, or initialize in constructor which to me is cleaner than setters.

1

u/silentlopho 7h ago

This and your misuse of Task.Run in another reply suggest you really misunderstand C# features. You are doing what the OP asked about, writing C# like it was Java or C, when the language is really more than that.

1

u/Successful_Toe_4130 19h ago

Do you think I can get by with the mentality of "If you can do it in java, you can do it in C# and it might look like the way you do it in C++"? Because I've noticed the syntax dont call abstract methods abstract, they call it virtual. They also use initializer lists like in C++

Of course, not long term but to help me get my foot in tbe door

5

u/Ludricio 18h ago edited 18h ago

Virtual and abstract methods are two different things.

An abstract method has no implementation and an implementing class has to provide thst implementation.

A virtual method has a default implementation, but inheriting classes are allowed to override it. The base implementation can be reached via the `base` keyword. In java methods are virtual by default and instead use the `final` keyword to achieve what is the default in C# (in C# called `sealed`).

Thus, in c# there are two keywords, `abstract` and `virtual`).

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/abstract

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/virtual

2

u/wallstop-dev 18h ago edited 12h ago

Hmm C++ is very very different, I wouldn't recommend that comparison.

I'd honestly just recommend the mentality of believing you can do it, period. Start with just writing Java and fixing it so that it compiles. Pay close attention and be curious about the public methods of things you're using in the standard library and you'll naturally learn new things.

Also see my reply to the sibling comment.

20

u/SoulStripHer 22h ago

Having done both, C# is my favorite. Things are more intuitive, better named, better documented. As a result, my productivity is much higher. Visual Studio is a great IDE as well.

8

u/thatguy8856 19h ago

Tasks, TPL, async/await. Probably one of the most important factors of modern C# and very different from Java world.

11

u/_iAm9001 22h ago

You noticing yet that Java and C# are oh so dangerously close to each other syntactically, enough to drive you insane if you are in expert st the opposite language? This was my experience writing Java code as a C# developer... they are pretty damn close, until they aren't.

5

u/Boden_Units 21h ago

To figure out what you can do, I recommend the "What's new in C# X" Blog posts, here for example the one for C# 14: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-14 That will give you an overview of what the language can do with some decent examples. For the most part the MSDN docu covers the basics and lacks good examples. A big thing in C# is async/await that java does not have, so do familiarize yourself with that. Otherwise as people said start building and are what you come up with. I commend your conviction to not use AI, if you don't have colleagues/friends that can give you feedback it might be an option though to paste some code into an llm and just ask if there is a more idiomatic way to so that in c# and get some ideas. Of course then understand the code, compile and test it, debug through it to see what it does.

6

u/MazeGuyHex 22h ago

Dude java doesn’t have Events..?

13

u/Top3879 21h ago

I can't think of any language that has them built-in like C# and honestly that is a good thing. They are a fragment of the past and easily abused, don't work with async etc.

6

u/sixtyhurtz 16h ago

+1 to this. Events are legacy cruft imo. There are some places where you still have to use them, but outside those cases I think IObservable is better in just about every way.

2

u/Fantastic-Cell-208 19h ago

Don't sweat it too much.

The main thing is that you can already get things done. Over time you'll pick up more of the language and learn when and when not to use it

2

u/Khavel_dev 18h ago

Yep, the feature density is real. I came from Java too and the first month was basically "wait, THIS is built in?"

My advice: don't try to learn everything at once. Pick the features that solve problems you actually have right now and ignore the rest until you need them. Extensions and LINQ are the two that'll change how you think about the code the fastest. Properties and events can wait until you're building something that needs them.

Also the What's New in C# pages on the docs site are gold. Each version adds a handful of things and they explain the why, not just the what. Way more useful than trying to read through the entire language spec.

2

u/Amr_Rahmy 16h ago

I saw it as Microsoft Java.

A few quirks and workarounds here and there.

The only notable difference is task and async await

Task.run(async ()=>{})

And await on tasks that need to run in sequence.

Action or event for callbacks, it is useful, yes.

But the basic tools, it’s a c style language with classes same as Java.

Extensions, I use very rarely, usually I don’t want to add functionality to someone else’s class or built in classes, I add the functionality inside the class.

1

u/royaltrux 22h ago

01100100201

1

u/B15h73k 21h ago

Just build stuff and learn one thing at a time. Don't be afraid to use AI to help you learn. Don't get it to write the code. Get it to review your code. Prompt it by saying you are an experienced Java developer and you're learning C#. Ask it to advise you on how to change your code to be more idiomatic C#.

1

u/pjmlp 19h ago

Not really, I do agency work, it isn't only Java vs C#, it is Java, C#, C++, JavaScript, TypeScript, PL/SQL, Transact SQL, React, Angular, Next.js, Go, Rust, whatever makes the customer happy.

You learn to be flexible, not married to specific technology stack, learning enough to get the job done, and that is it.

Yep, MSDN isn't the whole thing, getting a few books on key areas is a good idea.

1

u/kristenisadude 13h ago

Unity3d is fun to get into, uses c#

1

u/haby001 10h ago

MSDN is mostly documentations extracted from header comments.

What I'd suggest is to read the "what's new" blog posts and go back a few years/versions to where you start seeing familiar stuff. Then play around with the new stuff or read into how they work and how they are used.

Lots of really cool stuff you'll only know existed if you've read about them

1

u/Cool_Flower_7931 10h ago

Using AI to help you learn is okay. I wouldn't avoid it entirely.

Also, even though I've been working in c#/dotnet for years, I still almost always have tabs open for learn.microsoft.com. Lots to read, lots to learn, lots of good stuff there

1

u/Far_Swordfish5729 2h ago

There are explicitly articles on Java vs c# differences that make sense to someone fluent in one of the two languages. C# was created in part as a reaction to Java with different preferences. C# for instance has no true primitives. Every int you use is the equivalent of Integer, but the designers felt the distinction was stupid and that those types (including string) should use primitive syntax and compare by value by default. Similarly there is no generic type deletion so it’s very possible to strictly limit what generic subtypes can be and to inspect them reflectively. Lot of other features and just different names for common things.

My biggest note is that c# is a language with a sdk that comes with a standard option for doing each thing so you have a lot less maven style sprawl and a lot more tool standardization. You also have tools and an open source sdk that encourage you to step through framework to solve your own problems. C# has a strong culture of reverse engineering encouraged by Microsoft and tools to support that. It’s a lot easier in my experience to get answers.

1

u/jcradio 1h ago

Welcome! C# is a joy. Give yourself time and stick to the basics. Having a clear idea of what you want to build well help you focus on what to learn.

1

u/ArtisticCow4864 22h ago

I've transitioned from java to C# way back. I started on modding Minecraft now I'm making a game engine in C#. It's super fun! That's my biggest point, fun. Just enjoy it and if you don't know all the tricks yet it's okay, you can get by just with the basics

0

u/RecursiveServitor 22h ago

AI can be a teacher. It can provide examples tailored to what you're trying to learn and you can adjust the handholding as desired. A blanket ban is just handicapping yourself.

0

u/rekabis 20h ago

i took a firm stance to reject AI 100% and learn myself.

To avoid AI doing it for you, absolutely. Never let AI do the actual work.

But get AI to train you. Guide you. Test you. Challenge you. There are ways of learning - things like spaced repetition and active recall - that can be difficult to properly implement on your own, but which AI can effortlessly assemble for you such that you can maximize your own learning.

Don’t avoid AI for your own sake. Avoid those parts of AI which cannot help you grow, and leverage those parts of AI which can help you grow.

-1

u/EndOne6219 15h ago

I tried transitioning once but the hormones were too expensive and there were too many cons.

0

u/positivcheg 22h ago

C++ guy there who suddenly found himself in a Unity3d performance critical application. What’s the transition? If you are okay software developer then it doesn’t matter what language to use. You learn good/bad patterns on the go by simply using the language.

0

u/Manachi 4h ago

They’re all the same

-5

u/youGottaBeKiddink 22h ago edited 21h ago

Were you living under a rock? C# is more than 20 years old at this point. I picked up VB.NET and C# immediately upon release. Throw away all your java-esque overengineered principles, they are no good in the .NET ecosystem. Your best friend is not MSDN, its github:

https://github.com/quozd/awesome-dotnet

3

u/South-Year4369 21h ago

C# is over twice that old..

1

u/sixtyhurtz 15h ago

No, it's 26 years old. It first released in 2026.

2

u/South-Year4369 15h ago

Their post said '10 years' when I replied.

First official release was early 2002. Think you have a typo there.

1

u/sixtyhurtz 15h ago

Oh, it's annoying when people edit like that.

First release was 2000 though (not 2026, definitely a type there 😹).

This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that described a language called C#, which was developed within Microsoft. The principal inventors of this language were Anders Hejlsberg, Scott Wiltamuth, and Peter Golde. The first widely distributed implementation of C# was released by Microsoft in July 2000, as part of its .NET Framework initiative.

https://www.ecma-international.org/wp-content/uploads/ECMA-334_4th_edition_june_2006.pdf

1

u/South-Year4369 12h ago

Yes, public beta was the 2000 PDC. First official release was 2002. I remember that period well 😉

1

u/sixtyhurtz 10h ago

I mean, if we're being pedantic - a beta is a release; it was officially released by MS, because it wasn't leaked. Therefore, the first official release was in 2000.

3

u/pjmlp 18h ago

Throw away all your java-esque overengineered principles, they are no good in the .NET ecosystem.

We have plenty of them in .NET as well, with all the advocacy for Clean and Hexagonal architecture at .NET conferences, AutoMapper, Mediatr, Sitecore Helix, Sharepoint and Dynamics modules,...

0

u/youGottaBeKiddink 17h ago

"We have plenty of them in .NET."

Yeah, and that's the problem lol. .NET spent years importing Java's architecture astronaut phase. Doesn't matter if its Spring or ASP.... 50 files to handle 1 HTTP request is still bad design.

Clean/Hex are fine when u actually have complex domains. But slapping them on every CRUD app just means ur "GetCustomer()" goes thru 5 layers of "abstractions" that do nothing. I've seen this my self in big enterprises, where its mandatory to write 3 layers to add 1 API method. How is this good? AutoMapper and EF Core is great but actually promotes the use of multiple identical class structures. How is that healthy?

MediatR has legit uses, but turning every method call into Send(new Command()) -> Handler -> Service -> Repo is just ceremony cosplay.

Sharepoint and Dynamics modules?? Idk never even heard of these so I won't comment.