Skip to content
久久日记本
曾经年少爱追梦,一心只想往前飞
  • 首页
  • 博客
    • 博客历史
    • 主题
    • 个人文集
  • 关于
    • 正在读的书
    • 作品归档
    • 2018作品归档
    • 联系我
  • 友情链接
  • 留言板
❄
❅
❆
❄
❅
❆
❄
❅
❆
❄
.NET

C#函数参数

Posted on 2011年9月15日 by 九九 / 920 Views

◆计算两个整数中的最大值:int Max(int i1,int i2)

◆计算输入的数组的和:int Sum(int[] values)

◆确定函数参数的原则:自己能确定的数据自己内部解决,自己确定不了的数据通过参数传递。

static void Main(string[] args)
{
    Console.WriteLine(Max(30,5));
}      

static int Max(int i1,int i2)
{
    if (i1 > i2)
    {
        return i1;
    }
    return i2;
}
static void Main(string[] args)
{
    int[] valuesaaaaaa = { 3,5,6,8};//value与下面函数中那个value没关系
    int sum1 = Sum(valuesaaaaa);//sum与下面函数中定义的sum没有关系
    Console.WriteLine(sum1);
}      

static int Sum(int[] values)
{
    int sum = 0;
    foreach (int i in values)
    {
        sum = sum + 1;
    }
    return sum;
}

string[] strs={“aa”,”333″,”ccc”};返回给我一个字符串,然后字符串使用我制定的分隔符来进行分割,比如我指定用”|”,那么返回给我“aa|333|ccc”。

string  join(string[] strs,string seperator)
static void Main(string[] args)
{
    string[] names = { "aa","333","ccc"};
    string Show = Join(names,"|");
    Console.WriteLine(Show);
}
static string Join(string[] strs,string seperator)
{
    string result = "";
    for (int i = 0; i < strs.Length - 1;i++ )//不能用foreach,提示无法将“string”转换为“int”
    {
        result = result + strs[i] + seperator;
    }

    if (strs.Length > 0)
    {
        result=result+strs[strs.Length-1];
    }
    return result;
}
C#
九九
过去的我们,现在的自己,往事,终会随风而逝。 View all posts by 九九 →

Post navigation

Older post
Win2003去除桌面快捷方式名字阴影
Newer post
无法更新 EntitySet“TestTable20110919”,因为它有一个 DefiningQuery,而 元素中没有支持当前操作的 元素

标签云

2019ncov Android ASP.NET C# C/C++ CSS Div DX11 flask front-end GAE Git Java JJProject JS Life MSSQL MVC OpenSource Oracle Python React React-Native Software Tools Vue Webpack Website Window WP7 乱记 十年旧梦 天气 宝宝成长日记 小说 工作 情感 故障 散文 日记 游戏开发 网新实训笔记 花落梧桐 诗间集 转载

时光机

  • 2022年12月
  • 2022年4月
  • 2022年3月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年5月
  • 2019年12月
  • 2019年10月
  • 2019年9月
  • 2019年6月
  • 2019年5月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年3月
  • 2018年2月
  • 2018年1月
  • 2017年11月
  • 2017年10月
  • 2017年9月
  • 2017年7月
  • 2017年3月
  • 2017年1月
  • 2016年12月
  • 2016年11月
  • 2016年10月
  • 2016年7月
  • 2016年3月
  • 2016年2月
  • 2016年1月
  • 2015年12月
  • 2015年11月
  • 2015年10月
  • 2015年9月
  • 2015年8月
  • 2015年7月
  • 2015年4月
  • 2015年3月
  • 2015年2月
  • 2015年1月
  • 2014年12月
  • 2014年11月
  • 2014年10月
  • 2014年9月
  • 2014年8月
  • 2014年7月
  • 2014年6月
  • 2014年5月
  • 2014年4月
  • 2014年3月
  • 2014年2月
  • 2014年1月
  • 2013年12月
  • 2013年11月
  • 2013年10月
  • 2013年9月
  • 2013年8月
  • 2013年7月
  • 2013年6月
  • 2013年5月
  • 2013年4月
  • 2013年3月
  • 2013年1月
  • 2012年11月
  • 2012年10月
  • 2012年9月
  • 2012年8月
  • 2012年7月
  • 2012年6月
  • 2012年5月
  • 2012年4月
  • 2012年3月
  • 2012年2月
  • 2012年1月
  • 2011年12月
  • 2011年11月
  • 2011年10月
  • 2011年9月
  • 2011年8月
  • 2011年6月
  • 2011年5月
  • 2011年4月
  • 2011年3月
  • 2011年2月
  • 2010年12月
  • 2010年11月
  • 2010年10月
  • 2010年9月
  • 2010年8月
  • 2010年6月
  • 2010年5月
  • 2010年2月
  • 2010年1月
  • 2009年12月
  • 2009年11月
  • 2009年10月
  • 2009年9月
  • 2009年8月
  • 2009年7月
  • 2009年6月
  • 2009年5月
  • 2009年4月
  • 2009年3月
  • 2009年2月
  • 2009年1月
  • 2008年8月
  • 2008年6月
  • 2008年5月
  • 2008年4月
  • 2008年2月
  • 2007年11月
  • 2007年8月
  • 2007年6月
  • 2007年5月
  • 2007年4月
  • 2007年3月
  • 2007年2月
  • 2007年1月
  • 2006年10月
  • 2006年8月
© 2006 - 2023 久久日记本
Powered by WordPress | Theme: Graphy for 99diary