Array, how to erase an element and resize it

AlamaFromBe

Member
Joined
Jan 27, 2020
Messages
12
Programming Experience
10+
Hello,

I would like to be able to delete an element from an array and then reduce its size to the new size while keeping all the other elements.
I'm having a little trouble with the Net5 Framework, I'm looking for something like:
Example:
int myValue = myArrayObject.popAnResize(index X);
Which Classes would you suggest to me?
 
Thank you Sheeping, I will read a little, it will relax me :)

There you go, the idea of using a <Type> queue, I gave up because it is a FIFO stack system and I have no doubt that we can do a shuffle with it, but I am finishing for today. I learned what stuff, I'll tackle something else tomorrow.
I leave my job to help someone else if needed.

Lottery Class, geting 10 randoms numbers of 100 without duplicate:
//This is one algorytm proposition

using System;
using System.Collections.Generic;
using System.Threading;

public class Lotterie
{

    public static void Main()
    {

        /*_____________________________________________________________________________________________
        
                                         Creates and initializes a new ArrayList.
          _____________________________________________________________________________________________*/

        Console.WriteLine("\nRemplissage du panier\n");
        List<int> panier = new List<int>();
        for (int i = 1; i <= 100; i++)
        {
            Console.Write("    " + i);
            panier.Add(i);
        }
        Console.WriteLine("\n");

        /*_____________________________________________________________________________________________

                                                   get random 1 value
          _____________________________________________________________________________________________*/

        Random rnd = new Random();
        for (int i = 0; i <= 10; i++)
        {
            int indexList = rnd.Next(0, panier.Count);
            Console.WriteLine("Numéro tiré: " + panier[indexList]);
            panier.RemoveAt(indexList);
            //Console.WriteLine("Panier contient :" + panier.Count + " nombres");
            Thread.Sleep(2017);
        }

    }
}//end class
 
Try this small dll I made. It has less code than your code above, and you won't get duplicate numbers.
Reference it in your project, by right clicking your project, and click add reference. Browse to the dll, and select it.

Usage :
C#:
            Vriliancy_Digits vriliancy = new Vriliancy_Digits();
            Queue<int> result = vriliancy.CreateNumbers(Tuple.Create(1, 100));
Screenshot :

Screenshot_41.jpg

result.Dequeue(); will take the first number from the start of the queue. Stick this into a button click event or something, and you can take a new number just as if you are giving loto results.
Or in an iteration, but remember you can't modify a collection while inside the iteration of that same collection, so don't try and use result.Dequeue() method inside an iterator or you will get an error. Instead you can do this :
C#:
            foreach (int number in vriliancy.CreateNumbers(Tuple.Create(1, 100)))
            {
                Debug.WriteLine(number);
            }
Or, and I prefer this :
C#:
            using (Queue<int>.Enumerator number = vriliancy.CreateNumbers(Tuple.Create(1, 100)).GetEnumerator())
            {
                while (number.MoveNext())
                {
                    Debug.WriteLine(number.Current);
                }
            }
 

Attachments

  • VriliancyDigits.zip
    18.3 KB · Views: 9
Hello @Sheepings, the DLL is working great! :)
I implemented it by following the first proposition and using Dequeue ().
I have a simple console application that seems to not support Debug (or I don't know how) But it's okay, I'm using Console.

How do you see the content of a variable?
In AS3 we had a debugging tool that displayed the status of all variables. But with V.S. I don't know him well enough.

I'm curious, the algorithm of the DLL is that of Fisher thing?
Thanks for your time :)
 
@AlamaFromBe glad you like it.
On the line where you have Debug.WriteLine() - hover over debug, and you will see an icon appear. Then click that and click using System.Diagnostics; This will place the using System.Diagnostics; at the top of your code file with the rest of your using directives. Then to see the output of the debug.writeline method, you need to have the Output window visible in visual studio. To do that go to View Menu and Click Output. Or press Ctrl+w let go of w continue holding ctrl and press O. Then in your code when you see the debug.writeline method come up, you will see it print out the debug info from the writeline method to the output window.

In AS3 we had a debugging tool that displayed the status of all variables.
Read these
and

They will teach you how to use the debugger in visual studio.

I'm curious, the algorithm of the DLL is that of Fisher thing?
No, its my own implementation which does the same thing (more or less). Or atleast produces the same output as you wanted.
 
Back
Top Bottom