none
For Each Issue in WPF RRS feed

  • General discussion

  • I am having an issue with a for each in WPF trying to get it to out put what am i doing wrong

    Form1.cs
    
    
    namespace boxes
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
    
            private void button1_Click(object sender, EventArgs e)
            {
                
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                foreach green = new foreach();
                
                
     		textBox4.Text = green.person;
    
    
                }
    
    
         }
    }
    
    
    
    
    looparound.cs
    
    
    
        class foreach
        {
    
        
            public string person { get; set; }
            
            public void round()
            {
                List<string> demo = new List<string>();
    
                demo.Add("Bob");
                demo.Add("George");
                demo.Add("Tom");
                demo.Add("Sue");
    
                foreach (string person in demo)
                {
                    person.ToString();
                }
    
    
               
            }
        }
    }
    


    • Changed type Blue1535 Friday, April 5, 2019 6:44 PM
    Friday, April 5, 2019 1:29 PM

All replies

  • You are posting in the wrong forum. CS is not a script, it is a compiled language.  Post in the C# forum for assistance.


    \_(ツ)_/

    Friday, April 5, 2019 2:09 PM
  • This isn't a scripting question and would be better served in a different forum. But just a few thoughts on my part... Are you using Visual Studio as your IDE? How does it even compile? Aren't you getting errors?

    I am not a C# expert but there appears to be so much wrong with this. Example; typically you cannot name a class using a reserved word like foreach. 

      foreach green = new foreach();

    Are you taking a class or just trying to learn on your own? Don't hack away on your own. Take a programming class so that you can ask your instructor questions.   

    • Edited by MotoX80 Friday, April 5, 2019 2:23 PM
    Friday, April 5, 2019 2:17 PM