从另一个文件夹获取数据相同的解决方案 [英] get data from another folder same solution

查看:57
本文介绍了从另一个文件夹获取数据相同的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我有一个解决方案,其中包含一个名为"one"的文件夹,其中包含一个名为project.cs的.cs文件,我有一个字符串值,即字符串msg ="Hello"

同样的解决方案我有一个Form1.cs表单,我需要在其中拆分字符串并在datagrid中显示,但是为此,我需要在form1中获取字符串值msg?该怎么做?

即使我说一个.味精我也看不到味精intilesense.

我应该设定并获得财产吗?
在此先感谢

Hello,
I have a solution which consist of a folder called ''one'' which has a a .cs file called project.cs, I have a string value hear which is say string msg="Hello"

Same solution I have a form Form1.cs where I need to split the string and show in datagrid,but for that I need to get the string value msg in form1?How to do that?

even if i say one.msg i dont see msg intilesense.

Should i set and get as a property ?
Thanks in advance

推荐答案


Windows应用程序解决方案.
在a.cs文件中,像这样的公共字符串msg ="hello"一样声明您的变量.
从form1可以得到这样的值.
< a.cs类或文件的实例> .msg.toString().split(``Char'');

Hi,
Solution for windows application.
in a.cs file declare your variable like this public string msg="hello".
and from form1 you can get the value like this.
<instance of a.cs class or file>.msg.toString().split(''Char'');
i.e.
cls_a obja = new cls_a();
string[] strArr = obja.msg.toString().split('l');


如果您在第二个文件夹中创建了project.cs文件,Visual Studio可能会为其赋予一个新的命名空间,可能是称为one.因此,您将需要引用类似于one.project.msg这样的字符串变量.假定msg被声明为public.我还要说的是,将msg设为类project的公共属性会更好,因此您将拥有

If you created the project.cs file in the second folder, Visual Studio probably gave it a new NameSpace, probably called one. Therefore you would need to reference the string variable like this one.project.msg. This assumes that msg is declared as public. I would also say it would be better to make msg a public property of the class project, thus you would have

namespace one
{
    class project
    {
        public string msg { get; set; }
    }
}



并会喜欢它



and would refer to it liek this

<br />
one.project.msg

.

希望这对您有帮助

.

Hope this helps


文件名几乎无关紧要:与之相关的类(包括名称空间)的名称.
另一重要的是msg是否为静态字符串.如果不是,则只能通过包含它的类的实例来访问它-它不是孤立存在的,仅作为类实例的一部分存在.想想汽车:您不能在汽车"的手套箱中放置地图,而必须在这辆汽车",那辆汽车"或我的汽车"的手套箱中放置地图.汽车是课程,我的汽车"是一个实例.

然后您进入访问级别.从班级外部,您只能访问public项(这是一个谎言,但是完整的故事比当前需要的要复杂得多).因此,最好的方法是:
1)在项目类中的project.cs文件中,声明:
The name of the file is pretty much irrelevant: it is the name of the class (including the namespace) which is relevant.
The other thing which matters is whether msg is a static string or not. If it isn''t, then you can only access it via an instance of the class that contains it - it doesn''t exist in isolation, only as part of an instance of a class. Think car: you can''t put a map in the glovebox of "a car", you have to put it in the glovebox of "this car", "that car" or "my car". The car is the class, "my car" is an instance.

Then you come to access level. From outside the class, you can only access public items (this is a lie, but the full story is more complex than you need at the moment). So the best way to do it is:
1) Within the project class, in the project.cs file, declare:
public string msg { get; set; }

这将创建msg字符串作为类级别的公共属性.
2)在Form1中,声明项目类的实例,然后可以访问它的msg属性.

This creates the msg string as a class level public property.
2) In Form1, declare an instance of the project class, and you can access it''s msg property.

project myProject = new project();
myProject.msg = "Hello";



在这里,您仍然需要更改一些命名约定(类应以大写字母开头,因此应为Project而不是project,属性相同,再加上全名,而不是缩写:Message而不是msg,但这应该可以帮助您入门.



There are still a few things here you should change as far as naming conventions go (Classes should start with a Capital Letter, so it should be Project not project, Properties the same, plus they should have full names, rather than abreviations: Message rather than msg, but this should get you started.


这篇关于从另一个文件夹获取数据相同的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆