Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calling another class in another .cs file
Message
 
À
02/08/2002 14:38:18
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00685474
Message ID:
00685636
Vues:
14
I didn't realize you were using different projects. When that is the case, you do need to reference the project you need to access classes in. That is the way your current project knows where to look. Glad it's working.

>Thank you, this worked, but only after I added the second project into project1 as a reference.
>
>Thanks,
>
>Jerryt
>
>
>>You need to use "using namespace1;" in top of your .cs file
>>
>>
>>using System;
>>using namespace1;
>>
>>public class myclass2
>>{
>>
>>public static void Main ()
>>{
>>/// Access any exposed methods or properties of myclass1 like
>>myclass1 obj = new myclass1();
>>obj.mymethod();
>>}
>>
>>}
>>
>>
>>>Using C#.
>>>
>>>How can I access another class in a different .cs file.
>>>
>>>For example, how can I get myclass2 in namespace2 to access something in myclass1 namespace1?
>>>
>>>////////////////////////////////
>>>//one.cs
>>>using System;
>>>
>>>namespace namespace1
>>>public class myclass1
>>>{
>>> public string mystring = ""
>>>}
>>>////////////////////////////////
>>>
>>>////////////////////////////////
>>>//two.cs
>>>using System;
>>>
>>>namespace namespace2
>>>public class myclass2
>>>{
>>>
>>>public static void Main ()
>>>{
>>>///Access namespace1.myclass1 in one.cs here.
>>>}
>>>
>>>}
>>>////////////////////////////////
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform