标题:代码的结果运行不对
只看楼主
lhb62232397
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:117
专家分:546
注 册:2011-11-6
结帖率:75%
已结贴  问题点数:20 回复次数:8 
代码的结果运行不对
namespace _8ChuXu
{
    class Program
    {
        static void Main()
        {
            int p = 5;
            int q = 4;
            Program pro = new Program();
            pro.select(p, q);
            Console.WriteLine(p );
            Console.ReadLine();
        }
        public void select(int a, int b)
        {

            a += b;
        }
        
    }
}
就是最后结果运行不对,请求帮忙解决
搜索更多相关主题的帖子: void class public 
2012-01-17 11:52
月光雪山
Rank: 2
等 级:论坛游民
威 望:4
帖 子:36
专家分:97
注 册:2012-1-10
得分:20 
select()方法改为

public void select(ref int a,int b)

{
    a+=b;
}
2012-01-17 12:21
lhb62232397
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:117
专家分:546
注 册:2011-11-6
得分:0 
我附带个有的难度的问题
class config()
{        
public Socket ClientSocket;
        private void button1_Click_1(object sender, EventArgs e)
        {                                
            IPEndPoint ServerInfo = new IPEndPoint(IPAddress.Parse("127.0.0.1"), Convert.ToInt32(6000));
            Socket ClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            ClientSocket.Connect(ServerInfo);
            MessageBox.Show("连接成功!", "提示");           
        }
}
class program()
{   
        fmConfig pfmConfig = new fmConfig();
        public bool SendToClient(string data)
        {
            try
            {
                byte[] sendBuffer = new byte[10240];
                int dataLen = System.Text.Encoding.UTF8.GetBytes(data, 0, data.Length, sendBuffer, 4); //utf8编码
                sendBuffer[0] = 0x1F;
                sendBuffer[1] = 0xF1;
                CopyByte(sendBuffer, 2, dataLen, 2);
                dataLen += 4;
                pfmConfig.ClientSocket.BeginSend(sendBuffer, 0, dataLen, 0, new AsyncCallback(SendCallBack), pfmConfig.ClientSocket);//这条语句
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
}
上面的那条语句想调用config类中的ClientSocket,可以吗,有什么问题?
2012-01-17 13:29
月光雪山
Rank: 2
等 级:论坛游民
威 望:4
帖 子:36
专家分:97
注 册:2012-1-10
得分:0 
回复 3楼 lhb62232397
类名都不匹配呀
2012-01-17 18:10
lhb62232397
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:117
专家分:546
注 册:2011-11-6
得分:0 
哪些类名不匹配,可以具体指出来,我一一解决
2012-01-18 09:00
月光雪山
Rank: 2
等 级:论坛游民
威 望:4
帖 子:36
专家分:97
注 册:2012-1-10
得分:0 
回复 5楼 lhb62232397
fmConfig pfmConfig = new fmConfig();
与类Config
2012-01-18 12:31
lhb62232397
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:117
专家分:546
注 册:2011-11-6
得分:0 
class fmconfig()
{        
public Socket ClientSocket;
        private void button1_Click_1(object sender, EventArgs e)
        {                                
            IPEndPoint ServerInfo = new IPEndPoint(IPAddress.Parse("127.0.0.1"), Convert.ToInt32(6000));
            Socket ClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            ClientSocket.Connect(ServerInfo);
            MessageBox.Show("连接成功!", "提示");           
        }
}
class program()
{   
        fmConfig pfmConfig = new fmConfig();
        public bool SendToClient(string data)
        {
            try
            {
                byte[] sendBuffer = new byte[10240];
                int dataLen = System.Text.Encoding.UTF8.GetBytes(data, 0, data.Length, sendBuffer, 4); //utf8编码
                sendBuffer[0] = 0x1F;
                sendBuffer[1] = 0xF1;
                CopyByte(sendBuffer, 2, dataLen, 2);
                dataLen += 4;
                pfmConfig.ClientSocket.BeginSend(sendBuffer, 0, dataLen, 0, new AsyncCallback(SendCallBack), pfmConfig.ClientSocket);//这条语句
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
}
上面的那条语句想调用config类中的ClientSocket,可以吗,有什么问题?
抱歉,是我在论坛上写错了,现在改正确了。
可是怎么样才能正确调用,我调用的对吗
2012-01-18 14:55
月光雪山
Rank: 2
等 级:论坛游民
威 望:4
帖 子:36
专家分:97
注 册:2012-1-10
得分:0 
回复 7楼 lhb62232397
1.fmconfig()类没有修饰符,默认是私有的,不能再其他类中调用
2. private void button1_Click_1(object sender, EventArgs e)是触发的事件,没有触发Socket对象就没有实例化
2012-01-18 16:20
lhb62232397
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:117
专家分:546
注 册:2011-11-6
得分:0 
1、fmconfig类是公有的,可以在其他类中调用
2、button1_Click_1()是触发事件,触发完才调用ClientSocket的
那怎么样才能调用呢
2012-01-19 14:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-359773-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.509535 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved