Click here to Skip to main content
15,867,851 members
Home / Discussions / C#
   

C#

 
Question[Problem Solved] how to access a class of a file A.cs from other file B.cs Pin
jamesfrj23-Aug-12 13:33
jamesfrj23-Aug-12 13:33 
AnswerRe: how to access a class of a file A.cs from other file B.cs Pin
harold aptroot23-Aug-12 14:42
harold aptroot23-Aug-12 14:42 
GeneralRe: how to access a class of a file A.cs from other file B.cs Pin
jamesfrj30-Aug-12 0:25
jamesfrj30-Aug-12 0:25 
AnswerRe: how to access a class of a file A.cs from other file B.cs Pin
pramod.hegde23-Aug-12 20:12
professionalpramod.hegde23-Aug-12 20:12 
GeneralRe: how to access a class of a file A.cs from other file B.cs Pin
Pete O'Hanlon23-Aug-12 23:00
subeditorPete O'Hanlon23-Aug-12 23:00 
GeneralRe: how to access a class of a file A.cs from other file B.cs Pin
pramod.hegde23-Aug-12 23:04
professionalpramod.hegde23-Aug-12 23:04 
GeneralRe: how to access a class of a file A.cs from other file B.cs Pin
Pete O'Hanlon23-Aug-12 23:27
subeditorPete O'Hanlon23-Aug-12 23:27 
GeneralRe: how to access a class of a file A.cs from other file B.cs Pin
pramod.hegde23-Aug-12 23:51
professionalpramod.hegde23-Aug-12 23:51 
Few Points:
1. Its better to have namespaces & separate class files.
So, Cliente.cs would contain
C#
namespace TestNs
{
    public class Cliente
    {
        public string nome;
        public int codigo;
    }
}

and TestaCliente.cs would contain
C#
namespace TestNs
{
    class TestaCliente
    {
	static void Main()
	{
		Cliente c1 = new Cliente();
		c1.nome = "Rafael Consentino";
		c1.codigo = 1;
		
		Cliente c2 = new Cliente();
		c2.nome = "Jonas Hirata";
		c2.codigo = 2;
		
		System.Console.WriteLine(c1.nome);
		System.Console.WriteLine(c1.codigo);
		
		System.Console.WriteLine(c2.nome);
		System.Console.WriteLine(c2.codigo);
	} 
    }
}


2. Compile them.
csc TestaCliente.cs // this gives error. Because the compiler is not able to identify the reference class file.

Fix for it. Include the other referred files also.
csc TestaCliente.cs Cliente.cs       // You need to include as many classes as you refer.

This would create an .exe file.

3. Execute the generated .exe
..\Microsoft Visual Studio 10.0\VC>TestaCliente.exe

Result:
Rafael Consentino
1
Jonas Hirata
2


Hope I answered the question Smile | :)
GeneralRe: how to access a class of a file A.cs from other file B.cs Pin
Pete O'Hanlon24-Aug-12 0:04
subeditorPete O'Hanlon24-Aug-12 0:04 
GeneralRe: how to access a class of a file A.cs from other file B.cs Pin
jamesfrj24-Aug-12 4:44
jamesfrj24-Aug-12 4:44 
AnswerRe: how to access a class of a file A.cs from other file B.cs Pin
Bernhard Hiller23-Aug-12 22:51
Bernhard Hiller23-Aug-12 22:51 
GeneralRe: how to access a class of a file A.cs from other file B.cs Pin
jamesfrj30-Aug-12 0:30
jamesfrj30-Aug-12 0:30 
AnswerRe: how to access a class of a file A.cs from other file B.cs Pin
BobJanova23-Aug-12 22:54
BobJanova23-Aug-12 22:54 
GeneralRe: how to access a class of a file A.cs from other file B.cs Pin
jamesfrj30-Aug-12 0:22
jamesfrj30-Aug-12 0:22 
GeneralHow do I programmatically disable macros in Microsoft Project files using C#? Pin
Kosh201023-Aug-12 10:04
Kosh201023-Aug-12 10:04 
GeneralRe: How do I programmatically disable macros in Microsoft Project files using C#? Pin
BobJanova23-Aug-12 22:50
BobJanova23-Aug-12 22:50 
AnswerRe: How do I programmatically disable macros in Microsoft Project files using C#? Pin
Kosh201024-Aug-12 10:31
Kosh201024-Aug-12 10:31 
QuestionActive Directory Pin
mamoony23-Aug-12 7:49
mamoony23-Aug-12 7:49 
AnswerRe: Active Directory Pin
fjdiewornncalwe23-Aug-12 8:06
professionalfjdiewornncalwe23-Aug-12 8:06 
GeneralRe: Active Directory Pin
mamoony23-Aug-12 8:32
mamoony23-Aug-12 8:32 
GeneralRe: Active Directory Pin
fjdiewornncalwe23-Aug-12 8:42
professionalfjdiewornncalwe23-Aug-12 8:42 
GeneralRe: Active Directory Pin
mamoony23-Aug-12 8:46
mamoony23-Aug-12 8:46 
GeneralRe: Active Directory Pin
fjdiewornncalwe23-Aug-12 8:52
professionalfjdiewornncalwe23-Aug-12 8:52 
GeneralRe: Active Directory Pin
mamoony23-Aug-12 9:13
mamoony23-Aug-12 9:13 
GeneralRe: Active Directory Pin
mamoony23-Aug-12 8:48
mamoony23-Aug-12 8:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.