首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

在练习接口的时候提示,并非所有代码路径都有返回值?解决方法

2012-05-09 
在练习接口的时候提示,并非所有代码路径都有返回值?C# codeusing Systemusing System.Collections.Generi

在练习接口的时候提示,并非所有代码路径都有返回值?

C# code
using System;using System.Collections.Generic;using System.Text;namespace 接口练习{    public interface Ivehicle    {        int trumpet();    }    class Bike : Ivehicle    {        public int trumpet()        {            Console.WriteLine("I am bike 玲玲!");        }    }    class Bus : Ivehicle    {        public int trumpet()        {            Console.WriteLine("I am bus 叭叭!");        }    }    class Program    {                  static void Main(string[] args)        {            Bike dc = new Bike();            Bus gc = new Bus();            dc.trumpet();            gc.trumpet();            Console.ReadLine();      }        }    }


错误1“接口练习.Bike.trumpet()”: 并非所有的代码路径都返回值 1420接口练习
错误2“接口练习.Bus.trumpet()”: 并非所有的代码路径都返回值2320接口练习

 我哪儿错了?

[解决办法]
C# code
class Bike : Ivehicle    {        public int trumpet()        {            Console.WriteLine("I am bike 玲玲!");        }    }    class Bus : Ivehicle    {        public int trumpet()        {            Console.WriteLine("I am bus 叭叭!");        }    } 

热点排行