[问题] 关于方法与Form1 Load的问题

楼主: b8002012 (b8002012)   2018-12-07 18:27:30
各位前辈好
小弟在c#刚学不到一个礼拜,遇到一个问题
首先我在
private void Form1_Load(object sender, EventArgs e)
中定义一个阵列以及撰写了一个循环。
int compo = 255;
int[] mCPlts = new int[compo+1];
for (int i = 0; i <= compo; i++)
mCPlts[i] = i;
接着在别的button中撰写一个方法
private void FastBmpToBmp64(ref byte[] buf, string strFileName, ref int width,
ref int height, string PicPath)
其中这个方法里面另外撰写一个方法
Trans8GrayScale(paletteTest, mCPlts);
问题就是他说我的mCPlts不在我的内容内,但是我已经在Form1_Load运送完了,
我是有一个猜测,因为Form1_Load是private,在里面运算完的变量不可提供给其他的butt
on所使用…?
作者: konkonchou (卡卡猫)   2018-12-07 20:33:00
local global 是不同的
楼主: b8002012 (b8002012)   2018-12-07 20:53:00
k大:那意思是说Form1_Load中的MCplt只能在Form1_Load里面使用而已吗
作者: petercoin (彼得币)   2018-12-07 21:58:00
你在load里面宣告的就只能在里面用,拉到外面变globalvariale就可以了
楼主: b8002012 (b8002012)   2018-12-08 15:36:00
谢谢前辈们的帮忙,我想我理解了

Links booklink

Contact Us: admin [ a t ] ucptt.com