gpt4 book ai didi

c# - C#中的子程序

转载 作者:行者123 更新时间:2023-12-04 06:23:19 25 4
gpt4 key购买 nike

我对 C# 有点陌生,不太确定如何调用子例程。这是我想要做的:

private void button1_Click(object sender, EventArgs e)
{
// Call whatever subroutine you like
StartExstream();
}

public void StartExstream()
{
// Do Stuff Here
}

对我来说不幸的是,这不起作用。我收到“只有赋值、调用、递增、递减和新对象表达式可以用作语句”错误。

如何从我的 Button1_Click 事件调用我的 StartExstream 子?

谢谢,
杰森

编辑:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
// Call whatever subroutine you like
StartExstream();
}



public void StartExstream()
{
tcpExstream.Service1Client MyTCP = new tcpExstream.Service1Client();

string ExStreamPath;
string datPath;
string optPath;

// My Working Arguments
ExStreamPath = @"C:\Program Files\Exstream\Dialogue 6.1\Engine.exe";
datPath = @"-FILEMAP=DataFile,\\Dev-srv1\Exstream\LetterWriterApp\Input Files\Data Files\SAVEezkazivaftf40s452ndayb45.dat";
optPath = @"-CONTROLFILE=C:\Exstream\Development\LetterWriter\ControlFiles\Letter.opt";

// Hong's Arguments
//ExStreamPath = @"C:\Program Files\Exstream\Dialogue 6.1\Engine.exe";
//datPath = @"-FILEMAP=DataFile,C:\Exstream\development\AGDocGenerator\TempFiles\DataFiles\Data_456231_1598.xml";
//optPath = @"-CONTROLFILE=C:\Exstream\development\AGDocGenerator\ExstreamDialogue\ControlFiles\AGDocGenerator.opt";

// Kick It!
MyTCP.StartExStream(datPath, optPath, ExStreamPath);

// Extra line of code for breaking point
optPath = "nothing";
}
}

}

最佳答案

第一

如果例程在同一个类中,您可以直接通过编写它的名称来调用例程

Example

private void AnotherMethod()
{
// Call whatever subroutine you like
MyRutine();
}

第二

如果它不在同一个类中,您需要创建包含例程的类的实例,然后您可以使用该对象来调用您的例程
Example

MyClass c = new MyClass();
c.MyRutine();

关于c# - C#中的子程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6309742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com