Ok, So I am new to programming in general but getting a start with C#. I am still a near absolute beginner and just writing small projects to get comfortable with the language. I decided this was what I wanted to play with, SO first I created a class Deck, that holds a list of cards. This function is what I wanted to use to shuffle the cards. I do realize this is not the most efficient way but I wanted to accomplish a "Realistic" Shuffle. This is also a rough draft off the top of my head. The code works 1 time through, but Once i call deck.RemoveRange(0,52); It removes everything, from every list, Including NewDeck, FirstCut, SecondCut. (This is just a learning experiment for me and has nothing to do with "What is useful")
Edit: Apologies for the confusing code, I still vomit whatever is in my head until the computer understands. I meant to mention I knew that the issue was an issue with Refrence Types vs. Value Types, I was just under the impression that I was creating new Items when I was in fact, Not doing so. So I wondered how that applied to .RemoveRange and if that remove just an element or removed the base reference(Books and video's never explained this so I am trying to learn from this mistake).
public static List<Card> GetNewDeck(int ShuffleTimes)
{
Deck MainDeck = new Deck();
List<Card> NewDeck = MainDeck.DeckOfCards;
List<Card> ShuffledDeck = new List<Card>();
for (int i = 0; i <= ShuffleTimes; i++)
{
Random Shuffle = new Random();
var FirstCut = NewDeck;
var SecondCut = new List<Card>();
var deck = new List<Card>();
var cut = Shuffle.Next(15, 37);
for (int c = 0; c < cut; c++)
{
SecondCut.Add(FirstCut[0]);
FirstCut.RemoveAt(0);
}
while (deck.Count != 52)
{
var rif = Shuffle.Next(1, 4);
if (rif < SecondCut.Count)
{
for (int r = 0; r < rif; r++)
{
deck.Add(SecondCut[0]);
SecondCut.RemoveAt(0);
}
}
if (rif < FirstCut.Count)
{
for (int d = 0; d < rif; d++)
{
deck.Add(FirstCut[0]);
FirstCut.RemoveAt(0);
}
}
if (rif >= SecondCut.Count && SecondCut.Count != 0)
{
for (int ri = 0; ri <= SecondCut.Count; ri++)
{
deck.Add(SecondCut[0]);
SecondCut.RemoveAt(0);
}
}
if (rif >= FirstCut.Count && FirstCut.Count != 0)
{
for (int si = 0; si <= FirstCut.Count; si++)
{
deck.Add(FirstCut[0]);
FirstCut.RemoveAt(0);
}
}
if (deck.Count == 52)
{
NewDeck = deck;
}
}
deck.RemoveRange(0, 52);
ShuffledDeck = NewDeck;
}
return ShuffledDeck;
}