类里面嵌套了一个struct类型

weikeli19 2016-10-03 12:16:21
这是一个类里嵌套了一个struct 请问我标红的代码段struct是存放在堆里的还是存放在栈里的?我分析它应该是在栈里的 否则下面Main函数里不会报错。这段代码来自http://blog.csdn.net/onlyou930/article/details/5568319 只是我稍做了修改 把struct放到了类里面而已
代码如下:
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{

public class Draw
{
public struct Rectangle
{
private int _Width;
private int _Height;
public int Width
{
get { return _Width; }
set { _Width = value; }
}
public int Height
{
get { return _Height; }
set { _Height = value; }
}
public Rectangle(int width, int height)
{
this._Width = width;
this._Height = height;
}
}


private Rectangle _rect = new Rectangle(0, 0);

public Rectangle MyRect

{

get { return _rect; }

set { _rect = value; }

}

public Draw() { }

public Draw(int mapWidth, int mapHeight)

{

_rect = new Rectangle(mapWidth, mapHeight);

}
}
class Program
{

static void Main(string[] args)

{

Draw draw = new Draw();

draw.MyRect.Width = 20;//《== 编译错误

draw.MyRect.Height = 12;//《== 编译错误

}
}
}
...全文
419 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
weikeli19 2016-10-03
  • 打赏
  • 举报
回复
引用 4 楼 xuzuning 的回复:
我想,这里说的很清楚了 http://blog.csdn.net/u011974126/article/details/39610569
帮我回答一下 这个网页上的问题好吗 不难http://bbs.csdn.net/topics/392027431?page=1#post-401640728
weikeli19 2016-10-03
  • 打赏
  • 举报
回复
引用 1 楼 shingoscar 的回复:
类定义肯定不是在堆或者栈里
帮我回答一下 这个网页上的问题好吗 不难http://bbs.csdn.net/topics/392027431?page=1#post-401640728
xuzuning 2016-10-03
  • 打赏
  • 举报
回复
weikeli19 2016-10-03
  • 打赏
  • 举报
回复
没说到点子上
weikeli19 2016-10-03
  • 打赏
  • 举报
回复
引用 1 楼 shingoscar 的回复:
类定义肯定不是在堆或者栈里
car 你说的有点文不对题 你仔细看我的问题
Poopaye 2016-10-03
  • 打赏
  • 举报
回复
类定义肯定不是在堆或者栈里

110,534

社区成员

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

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

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