There is no single class or API call that will just do that. You will need to write some code and it depends on what you want to accomplish. Is this UDP or TCP? It this a specific type of service you are looking for? Maybe this particular service has a way to announce itself (like via broadcast or a centric service)? Do you have a list of IP addresses or ranges or you just want to query the entire network(s)?
And do you really need it to be a custom code? There are some excellent applications that can do just that, nmap being one of the most popular.
If you really need to write your own code to do that, start with .Net's "System.Net.Sockets" namespace, there are classes for raw sockets and TCP/UDP clients there. You will need to do roughly the following:
Again, all that is very much possible to do on your own but it is easier to do with utilities already tailored for that. Or try searching around for some components/libraries for C# that can do port scanning/sweeping.