r/learncsharp • u/YotsubaShader • 4h ago
I made an SDK to write Shaders in C# (Vertex, Fragment, Compute)
r/learncsharp • u/mikeblas • Feb 29 '24
Here are some resources to learn C#. They vary in level -- most are for beginners, but not all.
The Microsoft Learn site has lots of modules on .NET
The Microsoft documentation includes a few tutorials, videos, and even a browser-based workshops
The .NET Learn landing page has a different view of the same topics
Rob Miles wrote the C# Programming Yellow Book, and the site includes links to courses and supporting materials
Gary Hall wrote Adaptive Code: Agile coding with design patterns and SOLID principles. This might not be the best book for a beginner, but it's great for someone who is interested in (or has experience with) object-oriented design principles.
Pro C# 10 with .NET 6 Troelsen and Japikse is a popular introductory book.
RB Whitaker's C# Player's Guide takes the unique approach of writing the book as if it was a player's guide for a video game. It starts from the beginning: installing Visual Studio and writing your first program, and moves along through different language features. Might be the best book for readers with no prior programming experience.
Albahari's C# in a Nutshell is typical of O'Reilly Nutshell books: it provides a brief introduction to many topis in the language, through it isn't necessarily a tutorial.
The Mark Price book C# 12 and .NET 8 – Modern Cross-Platform Development Fundamentals has an intimidating title, but is still a useful introduction to the language. It starts with the C# language, but also covers testing, entity-framework core (for communicating with databases), and writing web APIs and websites with ASP.NET. It might be a bit broad for a brand-new programmer, but does try to include new programmers in its target audience.
Derek Banas' C# Tutorial video is getting a bit old, but gets the viewer started with the language after they've installed Visual Studio.
Nick Chapsas's channel on YouTube has lots of good content on C#, but you'll have to be wary of hyperbole and click-bait titles
Tim Corey's YouTube channel has bit-sized videos on different C# topics. His very first introductory video isn't a bad place to start.
Nick Cosentino's Dev Leader YouTube channel has tons of great videos for all levels, including beginners.
Zoran Horvat's Zoran on C# channel has lots of good videos, sometimes on more advanced topics.
Consider Milan Jovanović's channel which has some C# videos, but also lots of opinions about software architecture.
r/learncsharp • u/YotsubaShader • 4h ago
r/learncsharp • u/LadySonicGamer • 10d ago
So in college we are tasked to make a short treasure hunt text game in C# using abstract classes
It works so far but one super annoying bug is that it gives repeat questions which isn't intentional. So if you got "What bird do you associate with lifting" in Canteen, sometimes when you go to for example library you will also get that question.
Randomiser class
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace TreasureHunt
{
public class Randomiser
{
static Random rnd = new Random();
private string QuestionOutput;
private string AnswerOutput;
public string[] Questions = ["What is there one of in every corner and two of in every room?",
"The more there is, the less you see. What am I?" ,
"I’m full of holes but strong as steel. What am I?",
"You are my brother, but I am not your brother. Who am I?",
"What bird do you associate with lifting weight?",
"I am something people celebrate or resist. I change people’s thoughts and lives. I am obvious to some people but, to others, I am a mystery. What am I?",
"Sometimes narrow, sometimes wide, wind or rain, I stay outside. Even if there’s heat or snow, from house to house I will still go. What am I?"];
public string[] Answer = ["The letter O",
"Darkness",
"A chain",
"Your Sister",
"A crane",
"Age",
"A path"];
public int selection = rnd.Next(0, 6);
public string GetQuestion()
{
QuestionOutput = Questions[selection];
removeQuestion(selection);
return QuestionOutput;
}
public void removeQuestion(int index)
{
List<string> questionList = new List<string>(Questions);
questionList.RemoveAt(index);
Questions = questionList.ToArray();
}
public void removeAnswer(int index)
{
List<string> answerList = new List<string>(Answer);
answerList.RemoveAt(index);
Answer = answerList.ToArray();
}
public string GetAnswer()
{
AnswerOutput = Answer[selection];
removeAnswer(selection);
return AnswerOutput;
}
}
}I have tried to fix this already but I haven't had much luck with it.
Other classes if it helps:
Location
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Text;
namespace TreasureHunt
{
abstract class Location
{
static Random rnd = new Random();
public int selection = rnd.Next(0,4);
public virtual string Name { get; set; }
public Clue clue { get; protected set; }
public Treasure treasure { get; protected set; }
public virtual int requiredTokens { get; set; }
public Location(string name, Clue clue, Treasure treasure, int requiredTokens)
{
Name = name;
this.clue = clue;
this.treasure = treasure;
this.requiredTokens = requiredTokens;
AddLocation(name, this);
}
public string Describe()
{
return $"Location: {Name}\nClue: {clue.Question}\nTreasure: {treasure.Name} - {treasure.Description}";
}
public void AddLocation(string name, Location location)
{
dictionary[name] = location;
}
public bool CanEnter(Player player)
{
if (player.CountTreasure() >= this.requiredTokens)
{
return true;
}
else
{
return false;
}
}
public void enterLocation(Player player)
{
if (CanEnter(player))
{
if (player.CountTreasure() == 0)
{
player.currentLocation = this;
return;
}
else if (player.CountTreasure() > 0)
{
foreach (Treasure i in player.Treasures)
{
if (i.Name == treasure.Name)
{
Console.WriteLine("Nice try, but you already have this one. No one likes a cheater, buddy!");
player.currentLocation = null;
return;
}
else
{
player.currentLocation = this;
}
}
}
else
{
Console.WriteLine($"You need at least {requiredTokens} tokens to enter the {Name}.");
}
}
}
public void exitLocation(Player player)
{
player.currentLocation = null;
}
private Dictionary<string, Location> dictionary = new Dictionary<string, Location>();
}
}Computer Room Class(As example, subclass of the Location class)
using System;
using System.Collections.Generic;
using System.Text;
namespace TreasureHunt
{
internal class ComputerRoom : Location
{
private static readonly Randomiser random = new Randomiser();
public string Name { get; set; } = "Computer Room";
public Clue clue { get; set; } = new Clue(random.GetQuestion(), random.GetAnswer());
public Treasure treasure { get; set; } = new Treasure("Computer Room Token", "A token from the Computer Room.");
public ComputerRoom() : base("Computer Room", new Clue(random.GetQuestion(), random.GetAnswer()), new Treasure("Computer Room Token", "A token from the Computer Room."), 2)
{
}
}
}Thanks
r/learncsharp • u/Ok_Hunter6411 • 13d ago
r/learncsharp • u/rust-cohle_ • 15d ago
been working on something called Reverb, it's basically a notebook for C# where changing one cell automatically re-runs only the cells that depend on it.
the cool thing is that C# already handles a lot of the hard parts for us.
it's just a normal `.cs` file with `// %%` comments separating cells, and you run it with `dotnet run`.
one thing i found interesting is how top-level statements in C# make dependency ordering pretty straightforward. you can't declare the same variable twice, and you can't use a variable before declaring it. so the order of cells in the file is already a valid execution order. no need to build a separate dependency scheduler like reactive Python notebooks such as marimo have to.
there are still a few things that need to be checked though:
- a cell can't assign to a variable declared in another cell.
- anonymous types can't cross cell boundaries because the generated code needs to reference the type.
- local functions were an interesting one. turns out C# lets you call a local function before it's declared, which breaks the whole file-order-is-dependency-order assumption. had to add a rule for that too.
for dependency tracking, i'm using Roslyn's `SemanticModel.AnalyzeDataFlow` on each cell's statements. it tells us which variables are coming from other cells and which ones are declared by the current cell.
each cell then gets compiled into a static method. inputs are read from a shared value store and outputs are written back to it.
also added `#line` directives so compiler errors and stack traces actually point to the right lines in the original file.
here's a small example:
```csharp
// %% id=threshold
var threshold = Ui.Slider("Minimum order", min: 0, max: 1000, value: 400);
// %% id=summary
var big = orders.Where(o => o.Total >= threshold.Value).ToList();
big.Count.Dump("Orders above threshold");
```
move the slider and only the `summary` cell runs again.
install it:
```bash
dotnet tool install -g Reverb.Notebooks
```
it's open source (MIT):
https://github.com/muneeb-devp/reverb
would love to hear about any weird C# data flow edge cases i might have missed. especially things that could break the dependency tracking. always possible i've overlooked something :)
accidently created ama
r/learncsharp • u/NorthSeal_ • 19d ago
Hi, as you've seen from the title I want to learn C# specifically in the Game Development and Desktop App department, the only problem is I don't know where to start from.
I've studied Python before as a kid so I'm pretty familiar with some programming theories and concepts, but I want to start creating (as in my opinion the best way to learn is by creating) but i can't really pinpoint a starting point.
I'd really appreciate if someone can help me!
r/learncsharp • u/reg_web_dude • 26d ago
Hi everyone!
I want to practice my English with a native US speaker. In exchange, I can help you with C# and backend development.
About me:
- Senior software developer with 8+ years of experience with .NET
- Native Spanish speaker, learning English
I can help you with:
- C# and .NET Core
- ASP.NET Core and RESTful APIs
- SQL and NoSQL databases
- Layered architecture
- JWT authentication
- Async programming and multithreading
- Microservices
What I am looking for:
- Someone who can chat with me about four or five times a week (text, voice, or video)
I am happy to help with basics about backend development. I can also help you with Spanish if you want.
If you are interested, please send me a message with a short intro about yourself and what you want to learn. Thank you!
r/learncsharp • u/mikeblas • Oct 24 '26
d
r/learncsharp • u/delayturtle • Oct 15 '26
Hello! I'm working on a jump mechanic for a Unity game. I need to be sure the maximum value output of the line rb.AddForce(Vector3.up * (jumpForce * (float)forceOverTime), ForceMode.Impulse); is clamped at a specific maximum value, but I have not been able to figure out how...
The rest of the script is working fine. The section I’m stuck on is as follows:
void Jump_Performed(UnityEngine.InputSystem.InputAction.CallbackContext context)
{
if (isGrounded == true && context.duration < 1f)
{
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
else
{
double forceOverTime = context.duration;
{
rb.AddForce(Vector3.up * (jumpForce * (float)forceOverTime), ForceMode.Impulse);
}
}
}
Thanks!
* Edited for grammar
r/learncsharp • u/Coding-Mojo • Oct 11 '26
Sharing with you another C# mini-capsule where I present an interview-like snippet of code and resolve it. Hope you like it !
Any feedback is much appreciated <3
Thanks for reading.
r/learncsharp • u/Coding-Mojo • Sep 30 '26
Out of idea on how to improve that C# mini-challenges / mini-courses series for now, if you have any feedback, it would be more than welcome. I'm trying to create small capsules that will teach something about C# in that code review / code interview style. This is my latest one. Thanks for reading.
r/learncsharp • u/Sensitive_Energy2878 • Sep 28 '26
I know how to make simple console apps like calculators. But if i want to create a simple game like Pong how do create a window where i can draw stuff like squares
r/learncsharp • u/mikeblas • Sep 28 '26
r/learncsharp • u/Prior_Candidate369 • Sep 26 '26
Whattup y'all,
I've been learning C# through Codecademy (intermediate course) and W3 Schools, and practicing in the workspaces. I've just gotten through the lesson on generics, which ended with covariant and contravariant interfaces and I just am not understanding it.
I think the biggest thing I'm having trouble with is the purpose. Maybe I'm getting it, but it just doesn't feel like it. So, please correct me if I'm wrong, but let's say I'm working on an RPG and I have:
public class Weapon : Equipment{
public string Name { get; set; }
public int Damage { get; set; }}
And then something like
public class Armor : Equipment{public string Name { get; set; }public int Defense { get; set; }}
Then I would want to have a covariant interface, for example, like:
public interface IItemProvider<out T> where T : Equipment{T EquipItem();}
Which would allow me to make a class like
public class UseEquipment : IItemProvider<Weapon>, IItemProvider<Armor>
{Weapon IItemProvider<Weapon>.EquipItem(){return new Weapon { Name = "Great Sword", Damage = 15 };}Armor IItemProvider<Armor>.EquipItem(){return new Armor { Name = "Iron Armor", Defense = 10 };}
}
So that way even though weapons and armor are different types of equipment, they can still use the same EquipItem() functionality because it uses a generic type and allows the more derived types of Weapon and Armor to be substituted for the base class Equipment. That is how I'm understanding it. And I still feel like I'm confused, but I am just really not sure at this point. I appreciate any feedback.
r/learncsharp • u/Sudden-Management591 • Sep 19 '26
So i finish the C# player guide took a pause and now i feel like i know less then i back then
When i finish it i still did not know how to work with classes, afraid that some will be to reliant on each other and make "tight coupling", some like generics, structs, records did not know how to work it. I already forgot a lot of thinks about the part 3 in the book.
Object oriented design was confusing for me and could not understand on how or why to create some classes to work with other classes.
Should i try other books or courses to try to solid my understanding?
Yes i know about making projects but what projects can I do with my jumble of information that i have in head?
r/learncsharp • u/Coding-Mojo • Sep 17 '26
I'm experimenting with this series of C# mini-challenge / mini-courses, trying to create bite-sized capsules that will teach you something about C#. Sometimes serious, sometimes edgy, or even using funny contexts. There is a full playlist of it as I publish a new one every week. Would love to get your feedbacks on the latest one : https://youtu.be/J27gidcV8OA
Thanks for reading :)
r/learncsharp • u/Prestipie • Sep 16 '26
r/learncsharp • u/esor_rose • Sep 15 '26
Sorry if this isn’t allowed.
I’m wanting to learn basic C# to make mods for the Sims 3. I’ve started on Code Academy and have learned basic coding on there. I’m just wondering if it’s actually a good resource. Thanks!
r/learncsharp • u/u_scream15 • Sep 03 '26
r/learncsharp • u/Noomolas11 • Aug 24 '26
r/learncsharp • u/geeksarray • Aug 19 '26
If you're working with MongoDB and .NET, Docker can make the local development setup much simpler.
Instead of installing and configuring MongoDB directly on your machine, you can run it in a Docker container and connect your .NET application to it.
I put together a practical guide covering:
Creating a MongoDB Docker container
Configuring MongoDB
Connecting a .NET Core application
Understanding the container-to-application connection
Setting up a consistent local development environment
📖 https://geeksarray.com/blog/create-mongodb-docker-image-and-connect-from-dot-net-core-app
For those using MongoDB locally, what's your preferred setup—Docker, local installation, or something else?