C# Isn’t That Bad?

Abhishek Thakur
6 min readSep 24, 2024

C# often gets a bad rap for being too serious or too corporate. After all, it was born in the early 2000s at Microsoft, and a lot of its early use was in enterprise software development. But here’s the thing: C# isn’t all about spreadsheets, databases, or Windows forms. Underneath its suit and tie, C# is fun, flexible, and incredibly powerful.

In this article, I’ll show you why C# isn’t that bad by exploring its creative side with some fun examples. Whether you’re a beginner or someone looking to see a more lighthearted side of C#, you’re in the right place.

What is C#?

First, let’s cover the basics. C# (pronounced C-sharp) is an object-oriented programming language developed by Microsoft as part of its .NET framework. It’s strongly typed, which means that when you declare a variable, you must specify its type. While this may seem rigid, it actually helps catch bugs earlier and makes your code more predictable.

Now that we have that out of the way, let’s dive into the fun stuff!

1. C# and Visuals: Let’s Draw Some ASCII Art!

Who said C# is all about boring business logic? Let’s create a fun piece of art using just text. ASCII art has been a part of computer culture since the earliest days, and it’s a great way to get started with C#.

Here’s a C# program that draws a cute cat in your console window:

using System;
class Program
{
static void Main()
{
Console.WriteLine(" /\\_/\\ ");
Console.WriteLine("( o.o )");
Console.WriteLine(" > ^ < ");
}
}

If you copy and paste this code into a C# console application and run it, you’ll see a cute little ASCII cat staring back at you. Not too bad for such a serious language, right? This simple example introduces the Console.WriteLine method, which prints text to the console.

2. Random Story Generator: Let’s Get Creative

Want to take it up a notch? Let’s have some fun with randomization by creating a random story generator. This is a great way to practice using arrays, random numbers, and string manipulation.

Here’s a fun example where we create silly random stories:

using System;
class Program
{
static void Main()
{
string[] names = { "Alice", "Bob", "Charlie", "Diana" };
string[] places = { "the park", "the moon", "a haunted house", "the beach" };
string[] activities = { "baking a cake", "fighting zombies", "learning to juggle", "exploring hidden caves" };
Random rand = new Random();
string randomName = names[rand.Next(names.Length)];
string randomPlace = places[rand.Next(places.Length)];
string randomActivity = activities[rand.Next(activities.Length)];
Console.WriteLine($"{randomName} went to {randomPlace} to start {randomActivity}.");
}
}

This program randomly picks a name, a place, and an activity to generate a short, funny story. Every time you run it, the story will be different. Maybe Bob went to the moon to start fighting zombies, or Diana went to a haunted house to start baking a cake. Who knows?

This example introduces the Random class, which is used to generate random numbers. This makes your programs dynamic and unpredictable, which is especially fun in games or creative applications.

3. FizzBuzz: But Let’s Make It Silly

FizzBuzz is the classic coding problem often given in interviews. But instead of sticking to the boring “fizz” and “buzz,” let’s jazz it up.

For those unfamiliar, the idea is simple:

  • For numbers divisible by 3, print “Fizz.”
  • For numbers divisible by 5, print “Buzz.”
  • For numbers divisible by both, print “FizzBuzz.”
  • Otherwise, just print the number.

Here’s the standard FizzBuzz, but we’ll add a twist:

using System;
class Program
{
static void Main()
{
for (int i = 1; i <= 100; i++)
{
if (i % 3 == 0 && i % 5 == 0)
{
Console.WriteLine("JazzBuzz");
}
else if (i % 3 == 0)
{
Console.WriteLine("Jazz");
}
else if (i % 5 == 0)
{
Console.WriteLine("Bingo");
}
else
{
Console.WriteLine(i);
}
}
}

In this modified version, we’ve replaced “Fizz” with “Jazz” and “Buzz” with “Bingo” to give it a little more personality. This example uses if-else statements and the modulus operator (%) to check divisibility.

This may seem simple, but it teaches important concepts like loops, conditionals, and modular arithmetic.

4. Time for Some Emoji Fun: Let’s Get Expressive

Did you know that C# can handle emojis? Emojis are just Unicode characters, and C# works well with Unicode. Let’s build a simple emoji-based mood indicator.

using System;
class Program
{
static void Main()
{
Console.WriteLine("How are you feeling today? Choose a number:");
Console.WriteLine("1: 😀");
Console.WriteLine("2: 😢");
Console.WriteLine("3: 😡");
Console.WriteLine("4: 😎");
string choice = Console.ReadLine();
switch (choice)
{
case "1":
Console.WriteLine("Glad to see you're happy! 😀");
break;
case "2":
Console.WriteLine("Aww, cheer up! 😢");
break;
case "3":
Console.WriteLine("Whoa, take it easy! 😡");
break;
case "4":
Console.WriteLine("Stay cool 😎");
break;
default:
Console.WriteLine("Hmm, I don’t recognize that mood.");
break;
}
}
}

This program asks the user to pick a mood based on a number, and then responds with an appropriate emoji. The switch statement is a great way to handle multiple conditions, and it’s much cleaner than writing a bunch of if-else statements.

Plus, who doesn’t love a program that speaks in emoji?

5. Lambda Expressions: Making C# Look Super Cool

Okay, now let’s get a little more advanced, but stick with me! Lambda expressions in C# are a way to write anonymous functions (functions without a name). They can make your code more concise and are great for functional programming-style tasks like filtering or transforming data.

Let’s say you want to filter out only the even numbers from a list. You could write a traditional for loop, but lambdas let you do this in a single line!

using System;
using System.Linq;
class Program
{
static void Main()
{
int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var evenNumbers = numbers.Where(n => n % 2 == 0).ToList();
Console.WriteLine("Even numbers: " + string.Join(", ", evenNumbers));
}
}

In this example, n => n % 2 == 0 is the lambda expression. It says, “For each n, return true if n is divisible by 2.” We then use the Where method to filter the numbers, and string.Join to display them neatly. It’s a powerful and concise way to work with collections.

6. Building Mini-Games: The Rock-Paper-Scissors Game

C# can be used to build fun mini-games. Let’s create a simple Rock-Paper-Scissors game to explore basic game logic in C#.

using System;
class Program
{
static void Main()
{
string[] choices = { "Rock", "Paper", "Scissors" };
Console.WriteLine("Choose: Rock, Paper, or Scissors:");
string userChoice = Console.ReadLine();
Random rand = new Random();
string computerChoice = choices[rand.Next(choices.Length)];
Console.WriteLine($"Computer chose: {computerChoice}");
if (userChoice == computerChoice)
{
Console.WriteLine("It's a tie!");
}
else if ((userChoice == "Rock" && computerChoice == "Scissors") ||
(userChoice == "Scissors" && computerChoice == "Paper") ||
(userChoice == "Paper" && computerChoice == "Rock"))
{
Console.WriteLine("You win!");
}
else
{
Console.WriteLine("Computer wins!");
}
}
}

In this example, the player competes against the computer in a game of Rock-Paper-Scissors. The logic is simple: we compare the player’s choice to the computer’s and determine the winner. You’ll notice we use the Random class again to pick the computer's choice.

This teaches basic input handling, randomization, and logic building. Plus, it’s fun!

Final Thoughts: Why C# Isn’t That Bad

As you’ve seen, C# isn’t just for enterprise-level applications or formal, professional codebases. It’s versatile, powerful, and, yes, fun. From drawing ASCII cats to building random story generators, C# lets you experiment and be creative.

Whether you’re a complete beginner or someone exploring new ways to have fun with code, C# offers plenty of opportunities to express your creativity. So, give it a try, and soon you’ll see why C# isn’t that bad at all!

Happy coding!

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response