English 中文(简体)
通行证 C#中从File到File
原标题:Passing Variables From File-to-File in C#

我将如何使用<代码>Program.cs上宣布的变量,并从表格1.c获取该变量的价值?

我知道如何在C地这样做,但在Microsoft在C身上完全消失了。

方案:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using LuaInterface;

namespace WindowsFormsApplication1
{
    static class Program
    {
        public static Lua lua = null;
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
            lua = new Lua();
        }
    }
}

表格1.c

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;
using LuaInterface;

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

        private void button1_Click(object sender, EventArgs e)
        {
            lua.DoString("print( hi )");
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
        }
    }
}
最佳回答

采用<代码>Program.cs和Form1.cs等实例,假设这些实例为缺省名称,并附有<代码>。 方案 类别,即:Form1 类别,且贵方希望将一个参数通过 表格1:类别:

界定一个将这一参数和链条带至违约构造的<代码>Form1:

private Lua lua;

public Form1(Lua lua) : this()
{
   this.lua = lua;
}

在<代码>Program类别中,当值Form1时,将参数通过:

lua = new Lua();
Application.Run(new Form1(lua));

请注意,我正在使用OOP术语——目标和类别(而不是档案)。


最新情况:

自您宣布<代码>lua以来 http://www.un.org/Depts/DGACM/index_french.htm

Program.lua;

虽然你想在<>><>>>>>之前立即发出<代码>申请。 页: 1

不管怎么说,这让目标成为所有线索的公有资源——如果你有多面读,几乎是无法检测的,很难与他们合作。

问题回答

你们也可以使用参数。

Program.lua;

但是,肥胖症更清洁。

在主语中,必须在申请前对物体进行即时处理。 页: 1

    static void Main()
    {
        lua = new Lua();
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

在方案c中,最有可能是固定的一类:

static class Program
{
   ...
}

如果您宣布该变量为public,则您将能够从您的表格中查阅。

static class Program
{
    public static int myVariable;
    public static int MyProperty { get; set; }
}

您以表格形式向您提供变数和财产:

int i = Program.myVariable;
int j = Program.MyProperty;

在面向目标的方案规划中,你通常将变数保留在私人领域,只是宣布财产为公共性质。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...