Seperating Classes

  • Thread starter Thread starter Andrew G
  • Start date Start date
A

Andrew G

Hi,

am writing c# web applications and am trying to now seperate my code
into seperate DLLs. Mainly so that the code is easier to manage and I
can more easily 'plug in' seperatepieces of code without having to
trawl through a single page of thousands of lines of code.

is probably something simple but am having trouble finding the answer.

Basically I want a main DLL which is called by the .aspx page and then
below that I want seperate DLLs which hold different classes /
functions. the closest i have got is with the following :

FIRST DLL CODE :

using System;
using System.Web;
using System.Web.UI;

namespace WHATEVER.TEMPLATE.Web
{

public class TEMPLATEPage : System.Web.UI.Page
{
}
}
 
Hi,

am writing c# web applications and am trying to now seperate my code
into seperate DLLs. Mainly so that the code is easier to manage and I
can more easily 'plug in' seperatepieces of code without having to
trawl through a single page of thousands of lines of code.


is probably something simple but am having trouble finding the
answer.


Basically I want a main DLL which is called by the .aspx page and
then
below that I want seperate DLLs which hold different classes /
functions. the closest i have got is with the following :


FIRST DLL CODE :


using System;
using System.Web;
using System.Web.UI;
using GDD.WHATEVER;

namespace WHATEVER.TEMPLATE.Web
{


public class TEMPLATEPage : System.Web.UI.Page
{
public string strTest=setParameter.strTest();
}
}

in the second DLL I have :

using System;
using System.Configuration;
using System.Web.Mail;
using System.Web.UI;

namespace WHATEVER.CMN
{
public class setParameter
{
public string strTest()
{
return "Hello";
}
}
}

Ideally I would like to set some public variables in the second lot of
code that is accessible from the first and from the main .aspx pages
at the front.

When compiling i get the error :

An object reference is required for the nonstatic field, method or
property 'WHATEVER.CMN.SetParameter.strTest()'

also have got

'WHATEVER.CMN.SetParameter' is inaccessible due to its protection
level...?

pretty stuck, any ideas please...
 
ok third time lucky ;)

that top 'using GDD.WHATEVER; '

should read 'using WHATEVER.CMN; '
 
ok third time lucky ;)

that top 'using GDD.WHATEVER; '

should read 'using WHATEVER.CMN; '

You're trying to treat strTest as a static variable.

Try something like:

{

public class b
{
private string GetStrTest = c.strTest; //works as strTest is static
private string GetStrTest2; //set in constructor

public b() //constructor
{
c aC = new c();
GetStrTest2 = aC.strTest2; //strTest2 is not static so need to
create a c
}
}
public class c
{
public static string strTest = "test";
public string strTest2 = "test2";
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top