[英]What is syntax for creating a class in C# that would be equal to a Module in VB.net
I do almost all of my programming in VB.net (all flavors).我几乎所有的编程都在 VB.net(所有风格)中进行。 I am now been assigned a task to make a new routine in an existing C# application.我现在被分配了在现有 C# 应用程序中创建新例程的任务。 What I want to be able to do is pass a string variable to a class where I can figure out device type of a symbol handheld and figure out where an executable resides on device.我想要做的是将一个字符串变量传递给一个类,在那里我可以找出手持符号的设备类型并找出可执行文件在设备上的位置。 I am trying to keep the class to contain changes we make going forward in one place.我试图让课程包含我们在一个地方进行的更改。
so a brief description is on a screen there will be a button.所以简要说明在屏幕上会有一个按钮。 on that button click I want pass the text of the button to a (what would be a module in VB) a class and depending on text being passed and device type call a separate executable that lives on the device.在那个按钮上单击我想将按钮的文本传递给一个(在 VB 中是一个模块)一个类,并根据传递的文本和设备类型调用位于设备上的单独的可执行文件。
Everything I have tried so far has thrown errors.到目前为止我尝试过的一切都引发了错误。 On my button click i have在我的按钮上点击我有
String Reponse = clsCallAction("Activity");
but that gets a message that clsCallAction is a type but is used like a variable.但这会得到一条消息,表明 clsCallAction 是一种类型,但像变量一样使用。
here is the smaple of clsCallaction这是 clsCallaction 的示例
internal static partial class clsCallAction
{
public static object GetPath(object lAppName)
{
string resp = "";
if (lAppName.Equals("Activity"))
{
resp = @"\application\activity.exe";
}
return resp;
}
}
If I put new in front of the clsCallAction("Activity") on button click I get a cannot create instance of the static class 'clsCalACtion'如果我在单击按钮时将 new 放在 clsCallAction("Activity") 前面,我会得到一个无法创建静态类“clsCalACtion”的实例
appreciate any pointers.感谢任何指点。 very new at C# C# 非常新
It would look something like this:它看起来像这样:
public static class CallAction
{
public static object GetPath(object lAppName)
{
string resp = "";
if (lAppName.Equals("Activity"))
{
resp = @"\application\activity.exe";
}
return resp;
}
}
And would be used like this:并且会像这样使用:
String Reponse = CallAction.GetPath("Activity");
cls
不要用cls
前缀类object
if possible - it just makes everything harder work than it needs to be.. Kinda like calling everything "thing" - ("Put the thing in the thing and open the thing" is harder to understand than "put the key in the lock and open the door")尽可能避免使用object
- 它只会让一切变得比它需要的更难......有点像将所有东西称为“事物”-(“将事物放入事物中并打开事物”比“将钥匙放入事物中”更难理解锁并打开门")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.