none
newbie in c# with 2 questions RRS feed

  • Question

  • Hi Everyone!

    I have teo questions as stated:

    1)In which forum, or website, can I ask questions concerning syntax programming matters like  in my second question, which is

    2)  why don't I get 4 lines print  in my label? (simple program of a  click button an a label)

    private void button1_Click(object sender, EventArgs e)
            {
                int numberdvd = 0;
                int dvdprice = 0;

                string[] dvdarray = { "Streets of fire", "Star Wars", "Deep throat" };
               
                foreach (string movie in dvdarray)
                {
                    numberdvd = numberdvd + 1;
                    dvdprice = dvdprice + 3;

                    label1.Text = "le film loué est: " + movie + "\r\n";
                }
                    label1.Text = "Le cout total est: "  + dvdprice.ToString() + " pour " + numberdvd.ToString() + " loués";
                }


    I am beginning a bachelor's computer science degree at University Laval in Quebec next September (And will take english grammar classes too :-)  )  I'm trying to get ahead this summer, using all the learning tools Microsoft makes available for us.  That is really great, this MSDN section.

    Thank you All,

    Stef
     
    Thursday, June 11, 2009 1:14 AM

Answers

  • 1. This Forum is ok to post C# related syntaz etc. queries.

    2. Try this:

            private void button1_Click(object sender, EventArgs e)
            {
                int numberdvd = 0;
                int dvdprice = 0;
    
                string[] dvdarray = { "Streets of fire", "Star Wars", "Deep throat" };
    
                label1.Text = string.Empty;  // initializing label's text as empty text - ""
    
                foreach (string movie in dvdarray)
                {
                    numberdvd = numberdvd + 1;
                    dvdprice = dvdprice + 3;
    
                    label1.Text = label1.Text + "le film loué est: " + movie + "\r\n";  //adding each new text to previous one
                }
    
                label1.Text = label1.Text + "Le cout total est: " + dvdprice.ToString() + " pour " + numberdvd.ToString() + " loués";  //adding each new text to previous one
            }

    Regards, Lakra :) - If the post is helpful or answers your question, please mark it as such.
    • Marked as answer by King of Space Thursday, June 11, 2009 1:42 AM
    Thursday, June 11, 2009 1:22 AM

All replies

  • 1. This Forum is ok to post C# related syntaz etc. queries.

    2. Try this:

            private void button1_Click(object sender, EventArgs e)
            {
                int numberdvd = 0;
                int dvdprice = 0;
    
                string[] dvdarray = { "Streets of fire", "Star Wars", "Deep throat" };
    
                label1.Text = string.Empty;  // initializing label's text as empty text - ""
    
                foreach (string movie in dvdarray)
                {
                    numberdvd = numberdvd + 1;
                    dvdprice = dvdprice + 3;
    
                    label1.Text = label1.Text + "le film loué est: " + movie + "\r\n";  //adding each new text to previous one
                }
    
                label1.Text = label1.Text + "Le cout total est: " + dvdprice.ToString() + " pour " + numberdvd.ToString() + " loués";  //adding each new text to previous one
            }

    Regards, Lakra :) - If the post is helpful or answers your question, please mark it as such.
    • Marked as answer by King of Space Thursday, June 11, 2009 1:42 AM
    Thursday, June 11, 2009 1:22 AM
  • Thank you, I see the little trick you are doing by adding each new text to previous one.  In a way I had the answer just above  where I increment my integers.  It is nice to benefitiate of your experience :-)
    Thursday, June 11, 2009 1:48 AM
  • Yes. You have understood correctly the places where it could be used efficiently.
    Happy Coding! :)
    Regards, Lakra :) - If the post is helpful or answers your question, please mark it as such.
    Thursday, June 11, 2009 1:59 AM