473,324 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

denotes field where class expected and other problem

jm
I have snippets from Form1 and a class named netclass.cs (just an
arbitrary name.)

Form1 has a textBox1 on it. I want to reference it in the class. I
put:

static void Main()
{

Application.Run(new Form1());
netclass nc = new netclass(this);
netclass.StartClient();
}

In the netclass class:

public class netclass
{
static Form1 _Form;

public netclass(Form1 form)
{
_Form = form;
//
// TODO: Add constructor logic here
//
}

I get the error:

Keyword this is not valid in a static property, static method, or
static field initializer
(and it is talking about the keyword "this")

If I change the "static Form1 _Form;" to just "Form1 _Form;" I get
past that error, but then I get another error when I try an use the
_Form textBox1:

string temp = _Form.textBox1.Text; //in netclass.cs just want to get
the text

I can't figure out what to put to make them both go away.

Thank you for any help.
Nov 16 '05 #1
1 3679
Hi there...

1-. There's no way you can reference the this pointer within a static method
(ur doing it from within Main)

2-. The constructor expects to receive an object (ur passing it) then u
require to store that object into a member (it can't be static)
and ur doing it... Change the member definition from...

static Form1 _Form;

to this...

private Form1 _Form;

Regards,
--
Angel J. Hernández M.
MCSD


"jm" <jo*************@yahoo.com> escribió en el mensaje
news:c6**************************@posting.google.c om...
I have snippets from Form1 and a class named netclass.cs (just an
arbitrary name.)

Form1 has a textBox1 on it. I want to reference it in the class. I
put:

static void Main()
{

Application.Run(new Form1());
netclass nc = new netclass(this);
netclass.StartClient();
}

In the netclass class:

public class netclass
{
static Form1 _Form;

public netclass(Form1 form)
{
_Form = form;
//
// TODO: Add constructor logic here
//
}

I get the error:

Keyword this is not valid in a static property, static method, or
static field initializer
(and it is talking about the keyword "this")

If I change the "static Form1 _Form;" to just "Form1 _Form;" I get
past that error, but then I get another error when I try an use the
_Form textBox1:

string temp = _Form.textBox1.Text; //in netclass.cs just want to get
the text

I can't figure out what to put to make them both go away.

Thank you for any help.

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
4
by: ChrisB | last post by:
Hello All: I have created the following field within a class definition: Class User { // fields private RoleInfo roleInfo = RoleInfo.GetRoleInfo(Thread.CurrentPrincipal.Identity.Name);
3
by: Alex Sedow | last post by:
Why MSVC# compiler in this error example say that 'A' is a namespace? 'A' is a class, not a namespace. // lookup5.cs namespace Lookup { namespace Case5 { class D : B {
2
by: Dan | last post by:
I am going through a tutorial, and as far as I can see, have made no typing errors, However, the below code gives me the error message: >>>'dr' denotes a 'variable' where a 'method' was...
2
by: Patrick Olurotimi Ige | last post by:
I converted the code below from VB.NET to C# cos i have to add it to a C# application!! But i'm getting the error:- System.Data.SqlClient.SqlCommand.Parameters' denotes a 'property' where a...
3
by: Jim Heavey | last post by:
I create a class which would hold my static methods (methods I want to call without having to instantiate the class). I then attempted to use it in another class and I get the following error...
0
by: Ignacio Machin \( .NET/ C# MVP \) | last post by:
I'm getting an error "c:\inetpub\wwwroot\RGSSO\SO.aspx.cs(363): 'RGSSO.WebForm1.dataSetRG' denotes a 'field' where a 'class' was expected" on the following code: private void...
5
by: Jeremy | last post by:
I've got two projects, both reference system, system.data and system.xml and both include the using System.Xml.Serialization and using System at the top of the file. Both also include the...
4
by: colin | last post by:
How can I access a field contained in fieldInfo by reference so I can pass it to a function ? ive tried __refvalue but this needs a type known at compile time, I can access it with SetValue and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.