Sunday, 27 January 2013

C# How to fix error Type and identifier are both required in a foreach statement

To fix Type and identifier are both required in a foreach statement  

Watch online
Replace
            List<string> names = new List<string>();
            names.Add("One");
            names.Add("Two");
            names.Add("Three");
            names.Add("Four");
            names.Sort();
            string n;
            foreach(n in names){

                Response.Write(n);
            }
With
            List<string> names = new List<string>();
            names.Add("One");
            names.Add("Two");
            names.Add("Three");
            names.Add("Four");
            names.Sort();
           
            foreach(string n in names){
                Response.Write(n);
            }

No comments:

Post a Comment