locked
how to work with array in asp.net RRS feed

  • Question

  • User-519408813 posted

    Hallo again Guys, I have question,

    How to Implementacion in ASP ?

    $array_bobot = array();
    $array_nilai = array();
    for ($i = 1; $i < 10; $i++) {
    $_tjawab = "opsi_".$i;
    $_tidsoal = "id_soal_".$i;
    $jawaban_ = empty($p->$_tjawab) ? "" : $p->$_tjawab;
    $cek_jwb = $this->db->query("SELECT bobot, jawaban FROM m_soal WHERE id = '".$p->$_tidsoal."'")->row();
    $bobotnya = $cek_jwb->bobot;

    $array_bobot[$bobotnya] = empty($array_bobot[$bobotnya]) ? 1 : $array_bobot[$bobotnya] + 1;

    $q_update_jwb = "";
    if ($cek_jwb->jawaban == $jawaban_) {
    //jika jawaban benar
    $jumlah_benar++;
    $array_nilai[$bobotnya] = empty($array_nilai[$bobotnya]) ? 1 : $array_nilai[$bobotnya] + 1;
    $q_update_jwb = "UPDATE m_soal SET jml_benar = jml_benar + 1 WHERE id = '".$p->$_tidsoal."'";
    } else {
    $array_nilai[$bobotnya] = empty($array_nilai[$bobotnya]) ? 0 : $array_nilai[$bobotnya] + 0;
    $q_update_jwb = "UPDATE m_soal SET jml_salah = jml_salah + 1 WHERE id = '".$p->$_tidsoal."'";
    }

    $this->db->query($q_update_jwb);

    $update_ .= "".$p->$_tidsoal.":".$jawaban_.",";
    }

    Its koding in PHP, so plis help me for restore ke ASP ??

    Friday, May 15, 2020 10:36 PM

All replies

  • User323983933 posted

    Since this is posted in the MVC forum, I'll try to answer.

    There are several C# array types that might be of use here.  I am assuming you want to create some kind of library procedure that does this, as there isn't anything here that would be visible in a MVC page.

    I  am assuming your arrays are int arrays, as PHP doesn't seem to use strongly typed arrays.

    Also, not sure what kind of database you're trying to access here.  Most natural for ASP.NET MVC is SQL server.  Even more natural is to include the m_soal table in your applications Models and use Entity Framework on it.

    But to directly answer your question, there are multiple kinds of arrays. 

            public void ArrayHandlingMethod()
            {
                //ARRAYS 
                //this way loads data into the array on create.
                int[] bobotArray = new int[] { 1, 2, 5, 7, 9, 0 }; //loads an array on create
    
                //arrays another way, note that you can't change the length of arrays once they are created.  So you need a count up front.
                int[] BobotArray6 = new int[6];
                BobotArray6[0] = 1;
                BobotArray6[1] = 23;
    
                //this will loop through the array.
                foreach(int item in bobotArray)
                {
                    //do stuff
                }
    
                //this will also loop through the array
                for(int i=0;i<bobotArray.Length;i++)
                {
                    //do stuff
                }
    

    //LISTS List<int> bobotList = new List<int>();//creates empty bobotList.Add(1); //how to add items to the list bobotList.Add(12); //how to loop through the list foreach( int item in bobotList) { //do stuff } }

    Thursday, June 18, 2020 4:32 AM