zoukankan      html  css  js  c++  java
  • .NET 入门测试题四:函数

    (1) 下面两个函数都才能在错误,请指出这些错误.

    static bool Write()

    {

      Console.WriteLine("Text output from function.");

    }

    static void myFunction(string label,params int[] args,bool showLabel)

    {

      if(showLabel)

           Console.WriteLine(label);

      foreach (int i in args)

                     Console.WriteLine("0",i);

    }

    (2)创建一个应用程序,该程序使用两个命令行参数,分别把值放在一个字符串和一个整形变量中,然后显示这些值。

    (3)创建一个委托,在请求用户输入时,使用它模拟Console.ReadLine() 函数。

    (4)修改下面的结果,使之包含一个返回订单总价格的函数。

    struct

    {

      public string itemName;

      public int unitCount;

      public double unitCost;

    }

    (5)在order 结构中添加另一个函数,该结构返回一个格式化的字符串(一行文本,以合适的值替换用尖括号起来的斜体条目)。

    order Information:<unit Count><item name> item at $<unit cost> each,total cost $<total cost>

    答案:---------------------------------------------

    1:

    第一个  需要一个返回一个bool 值,没有return bool。

    第二个 用了parmas  就不能再用其它的参数了。

    2:

    if(args.Length != 2)

    {

      Console.WriteLine("Two arguments required.");

      return;

    }

    string param1 = args[0];

    int param2 = Convert.ToInt32(args[1]);

    Console.WriteLine(.........................)

    3:

    delegate string ReadLineDelegate();

    static void Main(string[] args)

    {

      ReadineDelegate readLine = new ReadLineDelegate(Console.ReadLine);

      string userInput= readLine();

         Console.WriteLine(userInput);

    }

    4:

    struct

    {

      public string itemName;

      public int unitCount;

      public double unitCost;

      public double TotalCost()

      {

        return unitCount * unitCost;

      }

    }

    5:

    struct order

    {

      public string itemName;

      public int unitCount;

      public double unitCost;

      

      public double TotalCost()

         {

        return unitCount * unitCost;

      }

      public string info()

      {

        return "Order information:"unit count:"+unitCount+",itemNmae:"+itemName+",item at $:"+unitCost+"each,total cost $"+TotalCost()+";

      }

    }

    以上资料来源于C# 入门经典.

  • 相关阅读:
    IMail不能发送邮件的解决方法
    asp.net防止刷新重新提交触发后台事件的方法
    你的网站被“白名单”了吗?
    网站权限引起的504错误的问题
    asp.net Web Service请求因 HTTP 状态 400 失败: Bad Request的原因
    对现有数据库的表做分区的方法
    测试 Cookie在不同浏览器内容长度限制的测试
    Thinkphp框架中使用memcache缓存的方法
    替换手机号中间数字为*号或隐藏IP最后位
    linux mysql 操作命令
  • 原文地址:https://www.cnblogs.com/markj/p/3053419.html
Copyright © 2011-2022 走看看