zoukankan      html  css  js  c++  java
  • C#函数的学习 分类: C# 20120514 00:51 567人阅读 评论(0) 收藏

    函数就是将一堆代码进行重用的一种机制。函数就是一段代码,这段代码可能有输入的值(参数),可能会返回值。一个函数就像一个专门做这件事的人,我们调用它来做一些事情,它可能需要我们提供一些数据给它,它执行完成后可能会有一些执行结果给我们。要求的数据就叫参数,返回的执行结果就是返回值。

    1)使用函数来连接字符串

    函数的参数必须制定参数类型,和返回值的类型

    static void Main(string[] args)
            {
                string str2 = SumString("abc", 3);
                Console.WriteLine(str2);
                Console.ReadKey();
            }
            static string SumString(string strBun,int nBtn )
            {
                string str="";
                for (int i = 0; i < nBtn; i++)
                {
                    str = str + strBun;
                }
                return str;
            }

    函数的所有路径都要有返回值,不能存在没有返回值的情况;

    namespace 调用函数分割字符数组
    {
        class Program
        {
            static void Main(string[] args)
            {
                string[] str2 = { "aa", "bb", "cc", "dd" };
                string strBre = "()";
                Console.WriteLine(BreakArray(str2, strBre));
                Console.ReadKey();
            }
            static string BreakArray(string [] str1,string strBreak)
            {
                string s = "";
                for (int i = 0; i < str1.Length - 1; i++)
                {
                    s = s + str1[i]+strBreak;
                }
                s = s + str1[str1.Length - 1];
                return s;
            }
        }
    }


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    通过Ambari2.2.2部署HDP大数据服务
    Ganglia监控安装配置
    Kafka安装配置
    Graylog2日志服务安装配置
    Dnsmasq域名解析系统安装配置
    在haoodp-2.7.3 HA的基础上安装Hbase HA
    MySQL5.6基于mysql-proxy实现读写分离
    MySQL5.6基于MHA方式高可用搭建
    CentOS使用yum安装drbd
    MySQL5.6基于GTID的主从复制配置
  • 原文地址:https://www.cnblogs.com/yisuowushinian/p/4715656.html
Copyright © 2011-2022 走看看