特殊的out和ref关键字
public void OutMethod(string str,out int length) {
    Console.WriteLine(str);
    length = str.Length;
}

public void RefMethod(string str, ref int length) {
    Console.WriteLine(str);
    Console.WriteLine(length);
    length = str.Length;
}

//Lua
require "luanet"

luanet.load_assembly("Lua")
Program = luanet.import_type("Lua.Program")

pro = Program()

void,length = pro:OutMethod("chicai")
print(void,length)

void,length = pro:RefMethod("chicai",1000)
print(void,length)

可以看出out和ref关键字在Lua中调用时,都会被当作返回值,void也会返回nil

其中out关键字声明的参数,直接不用传递参数过去


首页 我的博客
粤ICP备17103704号