locked
C# Doesn't recognize method RRS feed

  • Question

  • using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace dShell
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            ////METODLAR////
            public void ConsoleWriteLine(string text)
            {
                String.Concat(RTB.Text, text);
                String.Concat(RTB.Text, "\n");
            }
            ConsoleWriteLine("hi");
        }
    }

    So the "ConsoleWriteLine(); Doesn't work. I tried adding static but it broke "RTB" and caused me to rewrite all of the <g class="gr_ gr_162 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="162" id="162">project</g>.


    Saturday, November 17, 2018 8:11 AM

All replies

  • Hi,

    Every execution of a code starts with the Main() method. Since ConsoleWriteLine(string text) is a method, you should create a main method and then try executing ConsoleWriteLine("hi").

    Regards,

    Shreyash

    Saturday, November 17, 2018 8:53 AM
  • You have written a call to ConsloeWriteLine directly inside the class. This is not allowed, it has to be inside a method, and then the method inside the class.

    Saturday, November 17, 2018 9:06 AM
  • public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                ConsoleWriteLine("hi");
    
            }
            ////METODLAR////
            public void ConsoleWriteLine(string text)
            {
                String.Concat(RTB.Text, text);
                String.Concat(RTB.Text, "\n");
            }
        }
    


    Saturday, November 17, 2018 5:05 PM
  • Yes, now the syntax is correct. You are now calling the method from the constructor of Form1, so as soon as you create an instance of the class the method will execute (you are creating an instance from somewhere else, aren't you?)
    Saturday, November 17, 2018 10:10 PM