So the standard code to start the software ...

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace new_class { class Program { static void Main(string[] args) { Class1 klas1 = new Class1(); } } } 

and here he writes a mistake and xs what to do ...

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace new_class { class Class1 { public static **klas1**() { Console.WriteLine("123"); Console.ReadKey(); } } } 

I need to bring the software exactly 123 and it is from the class ..

Closed due to the fact that off-topic participants Denis Bubnov , Vadim Ovchinnikov , kmv , user194374, αλεχολυτ Jan 31 '17 at 16:03 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Vadim Ovchinnikov, kmv, Community Spirit
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Please give the error code - Mikhail Rebrov
  • public Class1() { Console.WriteLine("123"); Console.ReadKey(); } public Class1() { Console.WriteLine("123"); Console.ReadKey(); } - this is called the class constructor - Igor

1 answer 1

public static **klas1**()

The name of the method should not contain specials. characters. The method also needs to specify the type of the return value, in your case void .

 using System; public class Test { public class ExampleClass { public static void Write123() { Console.WriteLine("123"); Console.ReadKey(); } } class Program { static void Main(string[] args) { ExampleClass.Write123(); } } } 

As @Igor pointed out in the comments, you can simply add the output of the information you need to the class constructor. Then, when creating an instance of a class, the constructor will display it automatically.

 public class ExampleClass { public ExampleClass() { Console.WriteLine("123"); Console.ReadKey(); } } class Program { static void Main(string[] args) { new ExampleClass(); } }