May 092005
 

Because of the filesize, I decided to split up my main .cs file into smaller pieces. The namespace is E2O everywhere, and one of the files I created should hold all database-related stuff. So, it looks like this:


namespace E2O
{
public class DB
{
public DB()
{
//constructor
}

public static void xyz()
{
if(E2O.frmMain.checkbox1.Checked)
{
blabla...
}
}
}
}

Now why can’t I refer to checkbox1? The compiler gives the error:
An object reference is required for the nonstatic field, method, or property ‘E2O.frmMain.checkBox1’
The object is defined as public (not the default private), but I can’t get to it. HOW? I know, I should probably go out and buy a C# book, but the only thing I want to accomplish is make the maintainability a little easier, the functions work perfectly when they are in one big file.

If anybody knows, please comment, your help will be greatly appreciated.

 Posted by at 00:56

  3 Responses to “Learning C# – aargh!”

  1. I am sorry that I cannot help answer your question – I just wanted to make a different comment: I have been reluctant to start learning C# myself… However, while reading C# related web sites and forums, I always read about problems like the one you are experiencing. This basically is holding me back to starting the C# experience… 😉 I think I will stick with Delphi for a while longer…

  2. Hi James,

    I have a Pascal/Delphi background myself, but find myself more productive in C#. I’m not sure whether this is because of the .NET framework, or because of the language itself, but I like it a lot. So much that I really don’t want to go back. The problems I have is because I didn’t do any C# reading, but started developing anyway. My first product is almost done, and soon will be released. I am 100% sure that I could not have done the same product in Delphi in the same (short) amount of time.

    Perhaps Delphi.NET (Delphi2005) is good, but the IDE is so shitty, that in my eyes it ruins what Borland has build with previous versions of Delphi. I have Delphi6 Enterprise, but no way in the world will I upgrade to Delphi2005 if the quality of the IDE stays what it is now.

    Last week I got my VS.NET 2005 beta kit, and working with that is an even more satisfying experience. It looks good, works good, and produces fast code. Buying Delphi2005 now would mean another upgrade when .NET 2.0 goes live. It’s a rip off.

    Thanks for commenting!

  3. You are trying to call an instance member from a static method.
    Either remove the static from the xyz method declaration or make frmMain a static member and you should be sorted.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)