.NETGURU
C# File Includes
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcs' list.


Greg Bernhardt
I have a few files with constants that I want included in my web applications. How Do I include files in C#?

Greg Bernhardt
Forum Admin
http://www.physicsforums.com
Reply to this message...
 
    
Tim Musschoot
#using <namespacename>

where <namespacename> is the namespace defined in the file you wish to =
include. Also copy this file to the project directory.

----- Original Message -----
From: "Greg Bernhardt" <Click here to reveal e-mail address>
To: Click here to reveal e-mail address
Sent: Tue, 25 Jun 2002 04:13:23 -0500
Subject: C# File Includes
[Original message clipped]

Reply to this message...
 
    
Greg Bernhardt
how does this other file get compiled? is it a seperate dll then?
I'm usign VS.NET

thanks,
Greg
----- Original Message -----
From: "Tim Musschoot" <Click here to reveal e-mail address>
To: "aspngcs" <Click here to reveal e-mail address>
Sent: Tuesday, June 25, 2002 5:43 PM
Subject: [aspngcs] Re: C# File Includes

#using <namespacename>

where <namespacename> is the namespace defined in the file you wish to
include. Also copy this file to the project directory.

----- Original Message -----
From: "Greg Bernhardt" <Click here to reveal e-mail address>
To: Click here to reveal e-mail address
Sent: Tue, 25 Jun 2002 04:13:23 -0500
Subject: C# File Includes
[Original message clipped]

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
Tim Musschoot
Nope. All source files are compiled into 1 DLL. If you want separate =
DLL's, make an new project and add the source files to it. Compile it =
into a DLL. In the first project, you'll have to add the DLL to the =
project. You include the classes with #using <namespacename> again...

----- Original Message -----
From: "Greg Bernhardt" <Click here to reveal e-mail address>
To: Click here to reveal e-mail address
Sent: Tue, 25 Jun 2002 05:54:22 -0500
Subject: Re: [aspngcs] Re: C# File Includes
[Original message clipped]

To: "aspngcs" <Click here to reveal e-mail address>
Sent: Tuesday, June 25, 2002 5:43 PM
Subject: [aspngcs] Re: C# File Includes
[Original message clipped]

To: Click here to reveal e-mail address
Sent: Tue, 25 Jun 2002 04:13:23 -0500
Subject: C# File Includes
[Original message clipped]

Reply to this message...
 
    
Robert Chartier

If you have more than one project, create a reference to the second PROJECT
(not its outputted DLL). Makes life easier because it ensures the
dependencies, etc...

Right click the project that needs to use the other, Add Reference...,
choose "Projects Tab" and double click the second project, and then hit OK.

/rob

At 07:06 PM 06/25/2002 -0400, you wrote:
[Original message clipped]

Robert Chartier
Author and Developer
604-975-5590
Click here to reveal e-mail address
http://www.aspalliance.com/nothingmn/

Reply to this message...
 
    
Greg Bernhardt
ok let me get this straight. I make a cs file with all my constants and
make them under a namespace. Then compile it with my project and it will be
included into my regular project dll. Then all I have to do is put the
"using whatever" as the namespace?

Greg
----- Original Message -----
From: "Robert Chartier" <Click here to reveal e-mail address>
To: "aspngcs" <Click here to reveal e-mail address>
Sent: Tuesday, June 25, 2002 6:15 PM
Subject: [aspngcs] Re: C# File Includes

[Original message clipped]

Reply to this message...
 
    
Greg Bernhardt
btw, when I import the namespace correctly, how do I access my constants?

Greg
----- Original Message -----
From: "Robert Chartier" <Click here to reveal e-mail address>
To: "aspngcs" <Click here to reveal e-mail address>
Sent: Tuesday, June 25, 2002 6:15 PM
Subject: [aspngcs] Re: C# File Includes

[Original message clipped]

Reply to this message...
 
    
Koen De Waele
Why the need for putting your constants in a separate dll?

Just put them in a public class, if necessary with a custom namespace
and put this class in his own source file (constants.cs).
Add this class file in al the projects who needs this file, but maintain
the class only in one space.
(I'm assuming you do have a version control system)

Something like this:

File constants.cs:
Namespace company.util
{
    public class CUtil
    {
        const string CONST1 = "number one";
        const string CONST2 = "number two";
        const string CONST3 = "number three";        
        etc...
    }
}

Project A:

File projecta.cs
Namespace company.projecta
{
    using company.util;

    class CProjectA
    {
        string vara = Cutil.Const1;
        string varb = Cutil.Const2;
    }
}

Project B:

File projectb.cs:
Namespace company.projectb
{
    using company.util;

    class CProjectB
    {
        string vara = Cutil.Const2;
        string varb = Cutil.Const3;
    }
}

Note: if you use VS.net you have the added benefit of the intellisense
technology:
just type Cutil. and you have a list of the available constants.

My 2c,

Koen

[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3dy5hc3BsaXN0cy5jb20v
YXNwbGlzdHMvYXNwbmdjcy5hc3AgPSBKT0lOL1FVSVQNCgkNCg0K
Reply to this message...
 
    
TIM ELLISON
Ex:
Namespace Foo.Bar
{
    Public class AnotherClass
    {
        public const int WM_INS_FIELD = 0;
        public static const int WM_OUT_FIELD = 1;
    
    }
}

// and in other project.
using Foo.Bar;
namespace Bar.Foo
{
    public class ThisClass
    {
        public ThisClass()
        {
            // reference to static constant,
            // no need to construct class.
            int outField = Foo.Bar.AnotherClass.WM_OUT_FIELD;

            // need to construct to get this one.
            AnotherClass a = new AnotherClass();
            int infield = a.WM_INS_FIELD;
        }
    }            
}

Regards,

Tim Ellison
Senior Web Applications Developer,
Long and Foster Real Estate
703-359-1884
Click here to reveal e-mail address

-----Original Message-----
From: Greg Bernhardt [mailto:Click here to reveal e-mail address]
Sent: Tuesday, June 25, 2002 11:23 AM
To: aspngcs
Subject: [aspngcs] Re: C# File Includes

btw, when I import the namespace correctly, how do I access my constants?

Greg
----- Original Message -----
From: "Robert Chartier" <Click here to reveal e-mail address>
To: "aspngcs" <Click here to reveal e-mail address>
Sent: Tuesday, June 25, 2002 6:15 PM
Subject: [aspngcs] Re: C# File Includes

[Original message clipped]

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
Stewart Haddock
You will also want to look into setting constants on the web.config file for
global variables such as the 'dsn' or the admin email address.

example
-------------
<appSettings>
<add key="dsn" value="localhost;uid=MyUserName;pwd=;" />
<add key="msmqserver" value="server\myqueue" />
</appSettings>
------------

check out.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconformatofconfigurationfiles.asp

To access them.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconformatofconfigurationfiles.asp

Thanks
Stewart

-----Original Message-----
From: Koen De Waele [mailto:Click here to reveal e-mail address]
Sent: Wednesday, June 26, 2002 4:53 AM
To: aspngcs
Subject: [aspngcs] Re: C# File Includes

Why the need for putting your constants in a separate dll?

Just put them in a public class, if necessary with a custom namespace
and put this class in his own source file (constants.cs).
Add this class file in al the projects who needs this file, but maintain
the class only in one space.
(I'm assuming you do have a version control system)

Something like this:

File constants.cs:
Namespace company.util
{
    public class CUtil
    {
        const string CONST1 = "number one";
        const string CONST2 = "number two";
        const string CONST3 = "number three";        
        etc...
    }
}

Project A:

File projecta.cs
Namespace company.projecta
{
    using company.util;

    class CProjectA
    {
        string vara = Cutil.Const1;
        string varb = Cutil.Const2;
    }
}

Project B:

File projectb.cs:
Namespace company.projectb
{
    using company.util;

    class CProjectB
    {
        string vara = Cutil.Const2;
        string varb = Cutil.Const3;
    }
}

Note: if you use VS.net you have the added benefit of the intellisense
technology:
just type Cutil. and you have a list of the available constants.

My 2c,

Koen

[Original message clipped]

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
ghb@uwm.edu
Thanks for the tip stewart, I am using that connection tip. However, I have a
list of 50 or so constants that I need to use across 5 or 6 projects. Thats
why I need a seperate dll. btw, for all my projects in VS.NET, can I dump all
my dlls in one bin, but then seperate my projects into folders containing the
aspx files. Let me give you an example:

ROOT:
web.config
global.asax
/bin
all project dlls plus constant dll
/projects
/claims
claims web form
/checks
checks web form
/admin
admin web form

does this make sense? So that I don't need a bin for every project. Does this
work?

Quoting Stewart Haddock <Click here to reveal e-mail address>:

[Original message clipped]

Reply to this message...
 
    
Daniel Wilson
Greg,

This is from Tim earlier in this thread.
Ex:
Namespace Foo.Bar
{
    Public class AnotherClass
    {
        public const int WM_INS_FIELD = 0;
        public static const int WM_OUT_FIELD = 1;
    
    }
}

// and in other project.
using Foo.Bar;
namespace Bar.Foo
{
    public class ThisClass
    {
        public ThisClass()
        {
            // reference to static constant,
            // no need to construct class.
            int outField = Foo.Bar.AnotherClass.WM_OUT_FIELD;

            // need to construct to get this one.
            AnotherClass a = new AnotherClass();
            int infield = a.WM_INS_FIELD;
        }
    }            
}

As you can see it depends upon whether or constants are static or not.

-Daniel Wilson

-----Original Message-----
From: Greg Bernhardt [mailto:Click here to reveal e-mail address]
Sent: Tuesday, June 25, 2002 11:23 AM
To: aspngcs
Subject: [aspngcs] Re: C# File Includes

btw, when I import the namespace correctly, how do I access my constants?

Greg
----- Original Message -----
From: "Robert Chartier" <Click here to reveal e-mail address>
To: "aspngcs" <Click here to reveal e-mail address>
Sent: Tuesday, June 25, 2002 6:15 PM
Subject: [aspngcs] Re: C# File Includes

[Original message clipped]

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
 
System.Security.Cryptography.Xml.Reference




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification