C
Join ServerC#
help
❔ copy specific item from string array to another one
IIt's_Sam12/22/2022
( 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 !
& Also it's possible the user copy from second string array to the same copied one
How can i do it !
Bblinkbat12/22/2022
var options = new[] { "a", "b" };
var selections = Array.Empty<string>();
var userInput = Console.ReadLine();
if (options.Contains(userInput))
selections = selections.Concat(userInput);
IIt's_Sam12/22/2022
I didn't get it ! 😅
IIt's_Sam12/22/2022
@blinkbat
Bblinkbat12/22/2022
here we have an array of items, and if the input matches one of those items, it gets added to the second array
Bblinkbat12/22/2022
what are you trying to do?
IIt's_Sam12/22/2022
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
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
IIt's_Sam12/22/2022
@blinkbat
Bblinkbat12/22/2022
at that point i would make a simple class
Bblinkbat12/22/2022
public class Product
{
public double Price { get; set; }
public string Name { get; set; }
}
Bblinkbat12/22/2022
and just pass around instances of Product
AAccord12/23/2022
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.