运行以下代码时,出现“方法必须具有返回类型”的错误提示

yls552386119 2012-05-03 09:06:53
运行如下代码时,红色字体部分总是出现“方法必须具有返回类型”的错误提示,但是如果在corobotentity前加入void后,会出现“类型“ProMRDS.Simulation.Corobot.CorobotService”已经包含“CorobotEntity”的定义”粗无提示,这是什么原因呢?请各位高手指点!

代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml;
using corobot = ProMRDS.Simulation.Corobot;
using Microsoft.Ccr.Core;
using Microsoft.Dss.Core;
using Microsoft.Dss.Core.Attributes;
using Microsoft.Dss.ServiceModel.Dssp;
using Microsoft.Dss.ServiceModel.DsspServiceBase;
using W3C.Soap;
using submgr = Microsoft.Dss.Services.SubscriptionManager;

#region Simulation namespaces
using Microsoft.Robotics.Simulation;
using Microsoft.Robotics.Simulation.Engine;
using engineproxy = Microsoft.Robotics.Simulation.Engine.Proxy;
using Microsoft.Robotics.Simulation.Physics;
using Microsoft.Robotics.PhysicalModel;
using xna = Microsoft.Xna.Framework;
using xnagrfx = Microsoft.Xna.Framework.Graphics;
#endregion

namespace ProMRDS.Simulation.Corobot
{
[Contract(Contract.Identifier)]
[DisplayName("Corobot")]
[Description("Corobot service (no description provided)")]
public class CorobotService : DsspServiceBase
{
[Partner("Engine",
Contract = engineproxy.Contract.Identifier,
CreationPolicy = PartnerCreationPolicy.UseExistingOrCreate)]
private engineproxy.SimulationEnginePort _engineStub =
new engineproxy.SimulationEnginePort();
/// <summary>
/// Service state
/// </summary>
[ServiceState]
CorobotState _state = new CorobotState();
/// <summary>
/// Main service port
/// </summary>
[ServicePort("/Corobot", AllowMultipleInstances = true)]
private CorobotOperations _mainPort = new CorobotOperations();
[SubscriptionManagerPartner]
submgr.SubscriptionManagerPort _submgrPort = new submgr.SubscriptionManagerPort();
/// <summary>
/// Service constructor
/// </summary>
public CorobotService(DsspServiceCreationPort creationPort)
: base(creationPort)
{
}
/// <summary>
/// Service start
/// </summary>
protected override void Start()
{
base.Start();
SimulationEngine.GlobalInstancePort.Insert(new CorobotEntity("Corobot", new Vector3(0, 0, 0)));
}
///<summary>
/// An entity which represents a Corobot. This entity is created facing in the +Z direction meaning
/// that its front has positive Z coordinates. Front and Rear IR sensors are included along with a front-facing camera.
/// </summary>
[DataContract]
[DataMemberConstructor]
public class CorobotEntity : VisualEntity
{
private static float InchesToMeters(float inches)
{
return (float)(inches * 2.54 / 100.0);
}
/// <summary>
/// Default constructor used when this entity is deserialized
/// </summary>
public CorobotEntity()
{
}
/// <summary>
/// Initialization constructor used when this entity is built programmatically
/// </summary>
/// <param name="initialPos"></param>
public CorobotEntity(string name, Vector3 initialPos)
{
base.State.Name = name;
base.State.Pose.Position = initialPos;
}
public override void Initialize(xnagrfx.GraphicsDevice device, PhysicsEngine physicsEngine)
{
try
{
BoxShapeProperties chassisDesc = new BoxShapeProperties(
"chassis",
mass / 2.0f,
new Pose(new Vector3(0, chassisClearance + chassisDimensions.Y / 2.0f, 0)),
chassisDimensions);
chassisDesc.Material = new MaterialProperties("chassisMaterial", 0.0f, 0.5f, 0.5f);
BoxShape chassis = new BoxShape(chassisDesc);
chassis.State.Name = "ChassisShape";
base.State.PhysicsPrimitives.Add(chassis);
// platform
BoxShapeProperties platformDesc = new BoxShapeProperties(
"platform",
mass / 2.0f,
new Pose(new Vector3(0, platformClearance + platformDimensions.Y / 2.0f, 0)),
platformDimensions);
platformDesc.Material = chassisDesc.Material;
BoxShape platform = new BoxShape(platformDesc);
platform.State.Name = "PlatformShape";
base.State.PhysicsPrimitives.Add(platform);
}
catch
{
}
}
}
/// <summary>
/// Handles Subscribe messages
/// </summary>
/// <param name="subscribe">the subscribe request</param>
[ServiceHandler]
public void SubscribeHandler(Subscribe subscribe)
{
SubscribeHelper(_submgrPort, subscribe.Body, subscribe.ResponsePort);
}
...全文
723 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bcc222 2012-05-04
  • 打赏
  • 举报
回复
public void CorobotEntity(string name, Vector3 initialPos)
{
base.State.Name = name;
base.State.Pose.Position = initialPos;
}

方法是不是要加一个返回值啊?就是没有的话是不是前前面要写void啊?
不懂,坐等看热闹!
NewUser2008 2012-05-04
  • 打赏
  • 举报
回复
..... 方法必需声明返回类型 ,基本功啊
why0826001 2012-05-04
  • 打赏
  • 举报
回复
public class CorobotEntity 这个类,定义在public class CorobotService : 这个类里了,
yufei_yuxuan 2012-05-03
  • 打赏
  • 举报
回复
public class CorobotEntity 这个类,定义在public class CorobotService : 这个类里了,

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧