C
C#2y ago
Sam DZ

❔ copy specific item from string array to another one

( the order in copied one isn't matter ) & Also it's possible the user copy from second string array to the same copied one How can i do it !
6 Replies
blinkbat
blinkbat2y ago
var options = new[] { "a", "b" };
var selections = Array.Empty<string>();

var userInput = Console.ReadLine();

if (options.Contains(userInput))
selections = selections.Concat(userInput);
var options = new[] { "a", "b" };
var selections = Array.Empty<string>();

var userInput = Console.ReadLine();

if (options.Contains(userInput))
selections = selections.Concat(userInput);
Sam DZ
Sam DZOP2y ago
I didn't get it ! 😅 @blinkbat
blinkbat
blinkbat2y ago
here we have an array of items, and if the input matches one of those items, it gets added to the second array what are you trying to do?
Sam DZ
Sam DZOP2y ago
I'm doing like a backend with simple c# for college so i have 4 arrays ( 3 string & 3 double) 2 from the string are for products and 2 from the doubles for prices When the user want to add item to the cart they will copied to cart string array and the price will copied to double total price for cart @blinkbat
blinkbat
blinkbat2y ago
at that point i would make a simple class
public class Product
{
public double Price { get; set; }
public string Name { get; set; }
}
public class Product
{
public double Price { get; set; }
public string Name { get; set; }
}
and just pass around instances of Product
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