▲ 0 r/csharp

How does this go outside of the Array boundaries?

class SortingProgram
{ 
    static void Main(string[] args)
    {
        int[] Arr1 = [2,5,4,6,1,2,10,8,7,9];
        for (int i = 0; i < Arr1.Length; i++)
        {
            for (int c = 0; c < Arr1.Length; c++)
            {
                if (Arr1[c] > Arr1[c + 1])
                {
                    int tempLSR = Arr1[c + 1]; 
                    int tempGrt = Arr1[c];
                    Arr1[c] = tempLSR;
                    Arr1[c + 1] = tempGrt;
                }
            }
        }
        for (int R = 0; R < Arr1.Length; R++)
        {
            Console.WriteLine(Arr1[R]);
        }
    }
}

Apparently the if statement goes outside the array bounds, the array seems fine so idk what is going on

reddit.com
u/MaintenanceKlutzy431 — 1 month ago

Why does this not work and why is the sequence I wish to target considered invalid?

///step event
ViewMiddleX = camera_get_view_x(view_camera[global.CurrentCamera]) + (camera_get_view_width(view_camera[global.CurrentCamera]) / 2);
ViewMiddleY = camera_get_view_y(view_camera[global.CurrentCamera]) + (camera_get_view_height(view_camera[global.CurrentCamera]) / 2);
layer_sequence_x(TargetCard, ViewMiddleX);
layer_sequence_y(TargetCard, ViewMiddleY);



///create event
TargetCard = Sqn_LvL1introAlt
reddit.com
u/MaintenanceKlutzy431 — 2 months ago
▲ 0 r/csharp

Why isnt the program adding the items from the file into the combo box?

private void Form1_load(object sender, EventArgs e)
{
    string[] CollectionAppend = new string[5];
    if (File.Exists("SelectContent.txt"))
    {
        CollectionAppend = File.ReadAllLines("SelectContent.txt");
        for (int i = 0; i > CollectionAppend.Length; i++)
        {
            comboBox1.Items.Add(CollectionAppend[i]);
        }
    }
    else
    {
        string ErrMessage = "File not found!";
        string ErrCaption = "Error!";
        MessageBoxButtons buttons = MessageBoxButtons.OK;
        MessageBox.Show(ErrMessage, ErrCaption, buttons);
    } 
}

The file is located in the bin/debug folder and is not excluded from the project, what am I doing wrong here? the file clearly exists but it doesn't add the items into the combo box.

reddit.com
u/MaintenanceKlutzy431 — 3 months ago
▲ 0 r/csharp

This program is a rewritten version of a python program that I wrote a while back, the math works perfectly fine on the python program but it returns 0 here, why?

namespace C_Test
{

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public void ExampleFunc()
        {
            int Input1 = Int32.Parse(InputA.Text);
            int Input2 = Int32.Parse(InputB.Text);
            int ShellCount = (Input1 + Input2);
            double ShotChance = (Input2 / ShellCount) * 100;

            Result.Text = ShotChance.ToString();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            ExampleFunc();
        }
    }
}
reddit.com
u/MaintenanceKlutzy431 — 3 months ago

It may be just me, but I think that math is genuinely some of the coolest and greatest things we have ever come up with in human history.

Not only is it essential to literally everything ever and is a fundamental concept, its also super interesting to solve different problems with math and logic.

I don't know how there are people who think math is pointless dispite the fact that its the most important construct in society, its the very reason we have all the great things we have today.

reddit.com
u/MaintenanceKlutzy431 — 4 months ago