|
Few Points:
1. Its better to have namespaces & separate class files.
So, Cliente.cs would contain
namespace TestNs
{
public class Cliente
{
public string nome;
public int codigo;
}
}
and TestaCliente.cs would contain
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
TestaCliente.exe //this exe will be there in the same folder where you have your class files.
Result:
Rafael Consentino
1
Jonas Hirata
2
Hope I answered the question
|
|
|
|
|
You haven't actually answered the question that was asked. That question was really, why didn't the csc.exe compile the two class files together.
|
|
|
|
|
I have answered it. It was due to namespace. I have placed classes under a namespace and it works.
That's what I commented at last. 'Try this solution and the program should work'.
|
|
|
|
|
A couple of points. The practice of putting multiple classes in one file should be discouraged. It becomes harder and harder to keep separation in your classes if you can't even be bothered to separate your code - never recommend something that shouldn't be done in a professional environment; if you did it working for me, I would make you fix it.
Second, read the title of the thread - it's how to access a class in one file from another file. Not, what hack can I do to get round this.
So, you have not answered the question.
|
|
|
|
|
Few Points:
1. Its better to have namespaces & separate class files.
So, Cliente.cs would contain
namespace TestNs
{
public class Cliente
{
public string nome;
public int codigo;
}
}
and TestaCliente.cs would contain
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
|
|
|
|
|
You have, but you should reply to the OP here, not me. He doesn't get notifications of replies to me (one minor point, I would remove the Microsoft Visual Studio reference from the path as that could just end up confusing him).
|
|
|
|
|
Thank you, pramodhegde88! It worked perfectly.
|
|
|
|
|
Better use Microsoft Visual Studio. If you don't want to purchase a full version, you can get the "Express" edition for free. Just use the "Build" menu.
|
|
|
|
|
You're right. That happened because I was following a tutorial that does not use Visual Studio.
Thank you
|
|
|
|
|
When you're compiling a C# application or library, you have to include all the files you want to be compiled into the assembly.
If you want both of these files in the same assembly:
csc *.cs /out:TestaCliente.exe
or
csc TestaCliente.cs Cliente.cs
If you want a separate .dll for the first class, you can first create that with
csc /t:library Cliente.cs
... and then reference it like
csc TestaCliente.cs /r:Cliente.dll
In general, though, it makes more sense to use an IDE to manage your files as a project. I recommend SharpDevelop.
Edit: An IDE will do exactly the same thing, but it will construct the command for you even when it gets very complex, chain builds together for multiple assemblies and so on.
|
|
|
|
|
|
In SQL Server Integration Services (2008) I have a created a task script using C# that converts Microsoft Project (2010) MPP files to an ASCII text CSV format. The problem I have encountered is that because some of the files still have their macros enabled, the process stops and presents a window asking whether to "Enable" or "Disable" the file's macros. Because multiple files are being automatically processed, I need to set in the C# code a default of disabling all macros.
Does anybody know how to do this?
I tried the following, but couldn't get it to work because it would not recognize the "AutomationSecurity" item under Application. It returns the message: 'System.Windows.Forms.Application' does not contain a definition for 'AutomationSecurity'.
Application.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;
Here are the references being applied at the top of the class file.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using Microsoft.Office.Core;
using MSProject = Microsoft.Office.Interop.MSProject;
Thanks.
The science of business is the science of service, to this end it is better to do more than you promise than to promise more than you do.
modified 23-Aug-12 17:37pm.
|
|
|
|
|
Read the message. Application is being resolved to System.Windows.Forms.Application. I suspect you are trying to interact with an instance of some other application class you've instantiated through interop.
|
|
|
|
|
Once the C# class files were pulled over and fully applied in the SSIS Task Script, the popup box requesting to either Disable or Enable macros no longer appeared. There is no code in the Task Script for disabling the macros.
This is no longer an issue.
|
|
|
|
|
Hi I am new to active directory. I have an application in c# and want to use active directory login dialogbox in the application. I saw lots of code everywhere. Want to know how the login screen will popup. Is it automatic if you call code below?
DirectoryEntry userEntry = new DirectoryEntry(users.Path, LDAPUser, LDAPPassword);
ADUserDetail userInfo = ADUserDetail.GetUser(userEntry);
userlist.Add(userInfo);
}
directorySearch.Filter = "(&(objectClass=group)(SAMAccountName=" +fName + "*))";
SearchResultCollection results = directorySearch.FindAll();
Thanks in advance,
Sai
|
|
|
|
|
The code you have would be used to validate the entry a user has made in a login dialog, but you still have to show the login dialog before you can call this code.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Where can I find the log in dialog call. It is a windows c# applicatin.
Thanks,
Sai
|
|
|
|
|
There isn't one by default. You have to create it. (at least that is the case in Windows.Forms) If you are using WPF, I'm not entirely sure if there is a prebuilt component you can use.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Thanks,
So I have to create a login form using buttons and textboxes and then use the active directory code to verify the user?
Thanks,
Sai
|
|
|
|
|
correct.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Thank you .
|
|
|
|
|
How can I use WPF? I heard the name before. What is Active Directory Common Dialog and DirectoryObjectpickerDialog?
Thanks,
Sai
|
|
|
|
|
Those won't be what you want. If your application isn't already WPF you can't just use it. You would have to create a new project in WPF then.
Since you are using WinForms, you'll have to create a login dialog from scratch.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Hi Friends
I Want to Learn How to make Electronic Gadgets.
Currently I am developing ERPs using .Net2010 in C#.
I want to know from where, I should start.
Thanks..
Er. Varinder
|
|
|
|
|
Member 7820220 wrote: Electronic Gadgets
Sorry I am not seeing the connection between you wanting to create electronic gadgets and this being a programming site....
[Edit]
Check out
www.ghielectronics.com[^]
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
modified 23-Aug-12 9:55am.
|
|
|
|