In September 2023, MVPs and student ambassadors in Greater China started a series of intro C# talks under MVP Tech Gathering Station (MVP 聚技站), the Greater China MVPs’ livestream series on Microsoft Reactor. It followed the C# course on Microsoft Learn. This was episode 5, on methods (functions). The speaker was Microsoft MVP Zhang Anzhong, who has eight years of .NET experience and co-wrote a book on ASP.NET Core 5.0. I hosted, and also shared the teaching with him: I took the most basic parts.


What we covered
Three parts: the basics, a code demo, and going further.
What a method is. A named block of code: call its name and the statements inside run. Starting from the simplest SayHello(), adding a parameter to get SayHello("Tom"), and following how the program jumps into the method and back.
Why pull repeated code out. The example was a small program for medicine times: the same time-formatting code was written several times; pulling it into one method made the code shorter and easier to read. Along with it, an old rule: DRY, Don’t Repeat Yourself.

Treat a method as a “black box”. Only care about what goes in and what comes out; name each task first, then fill in the logic one by one.
An “interview question”. Imagine you’re in an interview and asked to write a program that checks whether an IPv4 address is valid: four numbers separated by dots, no leading zeros, each between 0 and 255. Think about how you’d break it into methods.

Recursion. Starting from the Chinese nursery story that never ends, “Once upon a time there was a mountain, and on it a temple, where an old monk told a young monk a story…”, then Russian dolls, then comparing recursive and loop versions of factorial.


Quiz. Three multiple-choice questions at the end: which line is a valid method signature, how to declare a method, how to call one. Scan to reply “.NET” and join the group to answer; prizes were a community mug and Zhang’s book.

Looking back
This was my first time hosting for MVP Tech Gathering Station. Half a year later I hosted an episode of its GenAI series: Managing multi-agent AI apps with .NET open source.