You need to spend a bit more time learning the syntax of C#, specifically about methods:
Methods (C# Programming Guide) | Microsoft Docs[
^]
At the class level, you are really only allowed to
declare things. There is a bit of a cheat here, because you can provide initializations for the things you declare. So, to some extent, you can also
do things (in a limited fashion).
Generally, if you want to do things they should be inside of a method. So, for example, the following would allow you to compile your code. Though, you'd need to add an invocation of the
DoSomeStuff
method elsewhere.
using System.IO;
namespace text
{
internal class Replace
{
string text = File.ReadAllText(@"C:\Users\OneDrive\Desktop\EDI_Examples_855_Orders\ftpedi.edi855_o_1397.EDI.16701");
internal void DoSomeStuff()
{
text = text.Replace("|", "*");
File.WriteAllText(@"C:\Users\Documents\test_shared_folder\EDITest3.txt", text);
}
}
}
This leaves the obvious chicken-and-the-egg question. If I need to do things in a method, and invoke the method, how does it all get started. That depends on the type of application. For console applications, this usually occurs in the
Main
method. For other applications, its usually in a method that is handling some external event and is called by the .NET framework when the event occurs.