调用对象,在主对象中获取和设置问题,语法错误 [英] Problems with calling object, get and set in main, syntax error

查看:82
本文介绍了调用对象,在主对象中获取和设置问题,语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是C#的新手,并且一直在鬼屋环境中从事迷宫游戏的项目.在研究了各种方法之后,我决定使用对象和链接列表.但是,尽管经过数周的尝试,我仍在努力处理代码 经过数小时的阅读文章和观看在线教程,我已经变得比以前更加困惑了.我想采用这种方法,而不是数组,因为我觉得这样更有效,而且操作更简单.我刚在想 一个简单的if/else结构的例子,但是对于这种级别的编码,我觉得它太乱了.任何帮助,建设性的批评或想法都将受到高度赞赏,因为我不想花那么多时间就放弃,但是我觉得它正在实现 观点.到目前为止,这是我的代码.在此先感谢:)

Hi, I am new to C# and have been working on a project for a maze game in a haunted house context.After researching different approaches I have decided to go with using objects and a linked list. However, despite weeks of trying I am struggling with the code and have gotten to the point after hours of reading articles and watching online tutorials that I am now more confused that ever before. I want to go with this approach rather than an array as I feel like this is more efficient and more OOP. I was thinking of going with a simple if/else structure but for this level of coding I feel it would be too messy. Any help, constructive criticism or ideas would be highly appreciated as I don't want to give up after so many hours spent on it but I feel its getting to that point. This is my code so far. Thanks in advance :)

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

推荐答案

这就是应该的样子.

This is what it is suppose to be.

https://msdn.microsoft.com/en-us/library/aa288470(v = vs.71).aspx

或者您可以使用自动属性.

Or you can use Auto properties.

https://msdn.microsoft.com/en-us/library/bb384054.aspx

public class Room
{
    public string RoomName {get; set;}
}

//some code using the object

Room room = new Room();

or 

var room = new Room();

room.RoomName = "Help"; // the set


var test = room.RoomName; //the get

同样,在发布代码时,您应该使用代码插入工具,该工具是在我用来将一些代码插入此回复帖子中的帖子时,在发布窗格顶部的HTML图标旁边显示的HTML图标旁边的图标.

Also when posting code, you should use the Code Insert tool, which is the icon next to the HTML icon you see as icons at the top of the posting pane when making a post that I have used to insert some code into this reply post.


这篇关于调用对象,在主对象中获取和设置问题,语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆