List and foreach loops in Windows Phone development

Source: Internet
Author: User

The concept of a set is not mentioned, so it is easier to store objects and facilitate value transfer.
Create a car class:

class Car{public string color {          get;          set;      }      public string name {          get;          set;      }}

P.s: simple and quick to create car attributes (with the get/Set Method ):
After you enter prop and tab, the public int myproperty {Get; set;} is automatically generated. Click continue tab, modify int, and modify myproperty in tab.
------------------------------------------------------

Create a list set:

List <car> mylist = new list <car> () {new car () {color = "red", name = "Red Flag"}, new car () {color = "green", name = "Hulk "}};

This method is also a fast and simple creation method, which consumes less resources and does not need to create two car object variables for reference.
The common method is as follows:

List <car> mylist = new list <car> (); car car1 = new car (); car1.color = "red"; car. name = ""; car car2 = new car (); car2.color = "green"; car. name = "Hulk"; mylist. add (car1); mylist. add (car2 );

------------------------------------------------

Foreach () loop:
The foreach () loop is basically the same as the for () loop, but foreach () is used to process the iteration of the Set element.

string mycars = "";    foreach(Car car in myList) {        mycars += car.name + "--" + car.color + Environment.NewLine;        }    mytextblock.Text = mycars;

Print result:
Red Flag-red
Hulk -- green

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.