How to use separate .cs files in C#?

后端 未结 7 470
没有蜡笔的小新
没有蜡笔的小新 2021-02-02 00:55

Forum; I am a newbie working out a bit of code. I would like to know the best way to use separate .cs files containing other classes and functions. As an example of a basic func

7条回答
  •  梦谈多话
    2021-02-02 01:41

    It is fairly simple to do. In your btClear.cs file simply generate a class definition like:

    public class MyUtility
    {
        public static void ClearContents(IEnumerable controls)
        {
            //TODO: Code that clears contents of controls passed
        }
    }
    

    Then you can call it from wherever the namespace the generated class is contained in is referenced via:

    MyUtility.ClearContents(SomeControlCollection);
    

    I hope I didn't completely miss the mark on your intention.

提交回复
热议问题