C#编程--函数

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        //声明一个函数
        static int readInt()
        {
            string s = Console.ReadLine();
            return Convert.ToInt32(s);
        }
        //空的返回值
        static void sayHello()
        {
            Console.WriteLine("hello");
        }
        //这个函数用来求和
        static int getSum(int a, int b)
        {
            return a + b;
        }
        //可变参数的函数
        static void VFunc(params string[] values)
        {
            foreach(string str in values){
                Console.WriteLine(str);
            }
        }

        // 函数的重载
        //函数的名字一样的
        static void PrintAge(string age)
        {
            Console.WriteLine(age);
        }
        static void PrintAge(int age)
        {
            Console.WriteLine(age);
        }
        static void Main(string[] args)
        {
            //函数
            PrintAge("123");
            PrintAge(23);
            Console.WriteLine(readInt());
            VFunc("2");
            VFunc("1", "2");
            VFunc();
            Console.ReadKey();
        }
    }
}
 

本文出自 “Kenan_ITBlog” 博客,请务必保留此出处http://soukenan.blog.51cto.com/5130995/1076240

发布了115 篇原创文章 · 获赞 0 · 访问量 3万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章