✅ is there anything wrong with how i used $"{}" ???

i am wondering
9 Replies
𓀠𓀒𓀡𓀬
𓀠𓀒𓀡𓀬OP10mo ago
using System; using System.Data; using System.Linq.Expressions; using System.Net.Security; using System.Diagnostics; using System.IO; using System.ComponentModel.DataAnnotations; using System.Xml.Schema; using System.ComponentModel.Design; namespace Program; class Bird { public string name; public string color; public int amount; public Bird(string name_bird, string color_bird, int amount_bird) { name = name_bird; color = color_bird; amount = amount_bird; } static void Main(string[] args) {
while (true) { Console.WriteLine("Please enter your parrot kind or 'q' to quit:"); string user = Console.ReadLine(); if (user.Length > 1) { Random random = new Random(); string[] parrots = { "Parrot", "Ara", "Sun conure", "Lovebird", "Cockatoo", "Macaws", "Lorikeets", "Scarlet Macaw", "Kākāpō", "Parakeets", "Senegal parrot", "Caiques", "Amazon parrot", "Parrotlet", "Burrowing parrot", "Cockatiel", "African Grey", "Eclectus", "Pionus parrot", "Budgerigar", "African Greys", $"{user}" }; string[] colors = { "Blue", "Red", "Green" }; Bird[] birds = new Bird[parrots.Length]; for (int i = 0; i < parrots.Length; i++) { int num = random.Next(1000, 20000); int start = random.Next(0, colors.Length); birds[i] = new Bird(parrots[i], colors[start], num); Console.WriteLine(birds[i].name); Console.WriteLine(birds[i].color); Console.WriteLine(birds[i].amount); Console.WriteLine(); } } else if (user == "q") { break; } } } } string[] parrots = { "Parrot", "Ara", "Sun conure", "Lovebird", "Cockatoo", "Macaws", "Lorikeets", "Scarlet Macaw", "Kākāpō", "Parakeets", "Senegal parrot", "Caiques", "Amazon parrot", "Parrotlet", "Burrowing parrot", "Cockatiel", "African Grey", "Eclectus", "Pionus parrot", "Budgerigar", "African Greys", $"{user}" };
Angius
Angius10mo ago
user is a string anyway So there's not really any point turning it into a string
𓀠𓀒𓀡𓀬
𓀠𓀒𓀡𓀬OP10mo ago
no im tryna put it at the end of my array
Angius
Angius10mo ago
Just put user there
𓀠𓀒𓀡𓀬
𓀠𓀒𓀡𓀬OP10mo ago
you have to create a hole new array if you want to use it diffently o
Angius
Angius10mo ago
No need for $"{user}"
𓀠𓀒𓀡𓀬
𓀠𓀒𓀡𓀬OP10mo ago
alr thx
i like chatgpt
i like chatgpt10mo ago
@Winter dissi Maybe you want to do something like this?
List<string> parrots =
[
"Parrot",
"Ara",
"Sun conure",
"Lovebird",
"Cockatoo",
"Macaws",
"Lorikeets",
"Scarlet Macaw",
"Kākāpō",
"Parakeets",
"Senegal parrot",
"Caiques",
"Amazon parrot",
"Parrotlet",
"Burrowing parrot",
"Cockatiel",
"African Grey",
"Eclectus",
"Pionus parrot",
"Budgerigar",
"African Greys"
];


string[] colors = { "Blue", "Red", "Green" };
List<Bird> birds = new();

// Displaying predefined birds
for (int i = 0; i < parrots.Count; ++i)
{
Bird bird = GetBird(parrots[i], colors);
birds.Add(bird);
Console.WriteLine(bird);
}

while (true)
{
Console.WriteLine("\nPlease enter your parrot kind or 'q' to quit:");
string? user = Console.ReadLine();

if (string.IsNullOrEmpty(user)) break;
if (user.ToLower() == "q") break;

parrots.Add(user);
Bird bird = GetBird(user, colors);
birds.Add(bird);
Console.WriteLine(bird);
}


Bird GetBird(string name, string[] colors)
{
string color = colors[Random.Shared.Next(0, colors.Length)];
int amount = Random.Shared.Next(100, 20000);
return new Bird(name, color, amount);
}

record Bird(string Name, string Color, int Amount)
{
public override string ToString() => $"Name: {Name}, Color: {Color}, Amount: {Amount}";
}
List<string> parrots =
[
"Parrot",
"Ara",
"Sun conure",
"Lovebird",
"Cockatoo",
"Macaws",
"Lorikeets",
"Scarlet Macaw",
"Kākāpō",
"Parakeets",
"Senegal parrot",
"Caiques",
"Amazon parrot",
"Parrotlet",
"Burrowing parrot",
"Cockatiel",
"African Grey",
"Eclectus",
"Pionus parrot",
"Budgerigar",
"African Greys"
];


string[] colors = { "Blue", "Red", "Green" };
List<Bird> birds = new();

// Displaying predefined birds
for (int i = 0; i < parrots.Count; ++i)
{
Bird bird = GetBird(parrots[i], colors);
birds.Add(bird);
Console.WriteLine(bird);
}

while (true)
{
Console.WriteLine("\nPlease enter your parrot kind or 'q' to quit:");
string? user = Console.ReadLine();

if (string.IsNullOrEmpty(user)) break;
if (user.ToLower() == "q") break;

parrots.Add(user);
Bird bird = GetBird(user, colors);
birds.Add(bird);
Console.WriteLine(bird);
}


Bird GetBird(string name, string[] colors)
{
string color = colors[Random.Shared.Next(0, colors.Length)];
int amount = Random.Shared.Next(100, 20000);
return new Bird(name, color, amount);
}

record Bird(string Name, string Color, int Amount)
{
public override string ToString() => $"Name: {Name}, Color: {Color}, Amount: {Amount}";
}
𓀠𓀒𓀡𓀬
𓀠𓀒𓀡𓀬OP10mo ago
damn that looks quite advanced i will look tommorrow if i can find anything good rn now im tryna do open source
Want results from more Discord servers?
Add your server