C#Struct堆栈

Struct若其内部含有堆对象,Struct的该对象放在堆上;

Struct当做参数传递时,其堆属性作为引用传递,值属性还是作为值传递;

struct TS

{

public int[] t1;

public int t2;

}

public void TF1(TS t)

{

int[] t1 = t.t1;

t1[0] = 2;

t.t2 = 20;

}

public void Main()

{

TS ts = new TS();

ts.t1 = new int[1];

ts.t1[0] = 1;

ts.t2 = 2;

TF1(ts);

Console.WriteLine(ts.t1[0]);

Console.WriteLine(ts.t2);

}

输出:

2

2

相关推荐
踏着七彩祥云的小丑5 小时前
pytest——Mark标记
开发语言·python·pytest
Dream of maid5 小时前
Python12(网络编程)
开发语言·网络·php
xiaoshuaishuai85 小时前
C# 接入 OpenClaw
windows·visualstudio·c#
W23035765735 小时前
经典算法:最长上升子序列(LIS)深度解析 C++ 实现
开发语言·c++·算法
Y4090015 小时前
【多线程】线程安全(1)
java·开发语言·jvm
不爱吃炸鸡柳6 小时前
Python入门第一课:零基础认识Python + 环境搭建 + 基础语法精讲
开发语言·python
minji...6 小时前
Linux 线程同步与互斥(三) 生产者消费者模型,基于阻塞队列的生产者消费者模型的代码实现
linux·运维·服务器·开发语言·网络·c++·算法
Dxy12393102166 小时前
Python基于BERT的上下文纠错详解
开发语言·python·bert
wjs20248 小时前
JavaScript 语句
开发语言