C
C#2y ago
uselessxp

❔ which is the key for write a good code? my 1st exercise of advent of calendar

Problem: https://adventofcode.com/2015/day/1 My code:
namespace AOC_2015_1
{
internal class Program
{
static short floor = 0;
static string? input;

static void Main(string[] args)
{
Console.WriteLine("Where should I delivery the next gift?");
input = Console.ReadLine();
gift_delivery(input);
}

static void gift_delivery(string input)
{
char floorUp = '(';
char floorDown = ')';

foreach (char c in input)
{
if (c == floorUp)
{
floor++;
}
else if (c == floorDown) {
floor--;
}
}
Console.WriteLine($"Final floor is {floor}");
}
}
}
namespace AOC_2015_1
{
internal class Program
{
static short floor = 0;
static string? input;

static void Main(string[] args)
{
Console.WriteLine("Where should I delivery the next gift?");
input = Console.ReadLine();
gift_delivery(input);
}

static void gift_delivery(string input)
{
char floorUp = '(';
char floorDown = ')';

foreach (char c in input)
{
if (c == floorUp)
{
floor++;
}
else if (c == floorDown) {
floor--;
}
}
Console.WriteLine($"Final floor is {floor}");
}
}
}
Do you think I wrote a good code? I could reduce code row number by deleting some var declarations like floorUp and floorDown but maybe it's not the right way.
7 Replies
uselessxp
uselessxpOP2y ago
maybe I could remove { } from the if statement since there's only 1 instruction in the middle
uselessxp
uselessxpOP2y ago
could it be a good idea?
ChucklesTheBeard
#code-review
uselessxp
uselessxpOP2y ago
oh, thanks just one thing, it seems Console.ReadLine(); is lenght limited, is there a way to make it accept more characters?
uselessxp
uselessxpOP2y ago
this is the string, it's not entirely pasted on the console, it seems it stops at 4094 lenght
Angius
Angius2y ago
Should be GiftDelivery not gift_delivery, it's C# not Python For the console not taking longer inputs, you can change that apparently: https://github.com/dotnet/runtime/issues/29029
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server