zoukankan      html  css  js  c++  java
  • C#第十四节课

    函数的调用

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

    namespace hanshu
    {
    class Program
    {
    //传值:四种方式
    //1.没有返回值,没有输入值
    //2.有返回值,没有输入值
    //3.没有返回值,有输入值
    //4.有返回值,有输入值


    //传址


    //(static/public) 返回类型 函数名 (参数类型,参数名)


    //没有返回值,没有输入值
    /// <summary>
    /// 累加求和,没有输入值,没有返回值
    /// </summary>
    public void Leijia()
    {
    Console.Write("请输入一个正整数");
    int a = int.Parse(Console.ReadLine());
    int sum = 0;
    for (int i = 1; i <= a; i++)
    {
    sum += i;
    }
    Console.WriteLine(sum);
    }
    //有输入值,没有返回值
    /// <summary>
    /// 累加求和,有输入值,没有返回值
    /// </summary>
    /// <param name="a"></param>
    public void Leijia(int a)
    {

    int sum = 0;
    for (int i = 1; i <= a; i++)
    {
    sum += i;
    }
    Console.WriteLine(sum);
    }
    /// <summary>
    /// 累加求和,没有输入值,只有返回值(int)
    /// </summary>
    /// <returns></returns>
    public int Leijia1()
    {
    Console.Write("请输入一个正整数");
    int a = int.Parse(Console.ReadLine());
    int sum = 0;
    for (int i = 1; i <= a; i++)
    {
    sum += i;
    }
    return sum;

    }
    /// <summary>
    /// 累加求和,有输入值(int),有返回值(int)
    /// </summary>
    /// <param name="a"></param>
    /// <returns></returns>
    public int Leijia1(int a)
    {
    int sum = 0;
    for (int i = 1; i <= a; i++)
    {
    sum += i;
    }
    return sum;
    }


    static void Main(string[] args)
    {
    Program pp = new Program();
    //Console.Write("请输入一个正整数");
    //int a = int.Parse(Console.ReadLine());
    //pp.Leijia(a);
    //pp.Leijia();
    //pp.Leijia();
    //int sum = pp.Leijia1();
    //Console.WriteLine(sum);
    //int sum=pp.Leijia1(6);
    //Console.WriteLine(sum);
    lei hanshu=new lei();
    hanshu.Leijia();
    haha heng = new haha();
    heng.hehe();

    Console.ReadLine();

    }
    }
    }

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

    namespace hanshu
    {
    class lei
    {
    public void Leijia()
    {
    Console.WriteLine("告诉我我成功了!!!!");
    }
    }
    }

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

    namespace hanshu
    {
    class haha
    {
    public void hehe()
    {
    Console.WriteLine("再告诉我我成功了!!!!");
    }
    }
    }

  • 相关阅读:
    [LeetCode] 582. Kill Process
    [LeetCode] 686. Repeated String Match
    [LeetCode] 341. Flatten Nested List Iterator
    [LeetCode] 404. Sum of Left Leaves
    [LeetCode] 366. Find Leaves of Binary Tree
    [LeetCode] 1485. Clone Binary Tree With Random Pointer
    [LeetCode] 459. Repeated Substring Pattern
    [LeetCode] 565. Array Nesting
    [LeetCode] 679. 24 Game
    [LeetCode] 364. Nested List Weight Sum II
  • 原文地址:https://www.cnblogs.com/xiongxiaobai/p/5272101.html
Copyright © 2011-2022 走看看