473,772 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with static methods

I didn't write this code so I'm not sure what is going on with this error.
checkedListBox1 is a public object. Why does the error say that it is
expecting a 'class' in a for loop? Is it because the method is static?
Here is the error and the code:

C:\...\Form1.cs (1130): 'APP.mainForm.c heckedListBox1' denotes a 'field'
where a 'class' was expected
public static void MenuItem_Click( object sender, System.EventArg s e)
{
for(int i = 0; i<checkedListBo x1.Items.Count; i++)//<<<<line 1130
{
checkedListBox1 .SetItemChecked (i,false);
}
}

Also getting an error saying: C:\...\newPromp t.cs(172): An object reference
is required for the nonstatic field, method, or property
'APP.mainForm.M enuItem'
private void button1_Click(o bject sender, System.EventArg s e)
{
for(int o = mainForm.histor yMenuItem.MenuI tems.Count-1; o>=0;o--)
mainForm.histor yMenuItem.MenuI tems.RemoveAt(o );

}

Help is appreciated.

Nov 15 '05
10 2213

Since your function is declared static, it can be called
without instantiation of your form class wich contains
the checkbox. Therefore your static function has know
way of knowing a checkbox exists. Why are you using a
static function here anyway?

I hope that makes sense.
-----Original Message-----
I didn't write this code so I'm not sure what is going on with this error.checkedListBox 1 is a public object. Why does the error say that it isexpecting a 'class' in a for loop? Is it because the method is static?Here is the error and the code:

C:\...\Form1.c s(1130): 'APP.mainForm.c heckedListBox1' denotes a 'field'where a 'class' was expected
public static void MenuItem_Click( object sender, System.EventArg s e){
for(int i = 0; i<checkedListBo x1.Items.Count; i++)//<<<<line 1130{
checkedListBox 1.SetItemChecke d(i,false);
}
}

Also getting an error saying: C:\...\newPromp t.cs(172): An object referenceis required for the nonstatic field, method, or property
'APP.mainForm. MenuItem'
private void button1_Click(o bject sender, System.EventArg s e){
for(int o = mainForm.histor yMenuItem.MenuI tems.Count-1; o>=0;o--) mainForm.histor yMenuItem.MenuI tems.RemoveAt(o );

}

Help is appreciated.

.

Nov 15 '05 #11

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

Similar topics

5
15848
by: GIMME | last post by:
One of my coworkers insists that one should never use static methods because race conditions exist. Thinking along the lines that all variable assignments are assignments to static variables. He's wrong. Right? Two users in a web session could both access a static method at the same time and never have any trouble.
9
1980
by: Simon Harvey | last post by:
Hi all, In my project I have made a number of helper methods static. As I understand it, this will create the problem that multiple threads could access the static method at the same time and interfere with one another. My question is, for each static method, do I need to lock access to only one call at a time? I've noticed that Microsofts Data Application block also uses static methods for its data access calls - for example execute...
3
2088
by: Jay | last post by:
Why are there static methods in C#. In C++ static was applied to data only (I believe) and it meant that the static piece of data was not a part of the object but only a part of the class (one copy of data as opposed to multiple instances of the class) C# is now applying the static concept to methods. Why?, I thought that only one copy of the methods were loaded into memory not matter how many instances were created. Is this different...
9
4161
by: Clint | last post by:
Hey all - Excuse the cross-post ... I'm not sure what the appropriate newsgroup would be for this question. I have a question that I'm not quite sure how to ask. For all I know, I have the verbaige completely wrong, but here goes nothing ... I'm currently using the MS Data Access Block for a desktop application I'm writing. Recently, I had to add a call to a web service, which in
17
2355
by: Picho | last post by:
Hi all, I popped up this question a while ago, and I thought it was worth checking again now... (maybe something has changed or something will change). I read this book about component oriented design (owreilly - Juval Lowy), and it was actually very nice. The book goes on about how we should use Interfaces exposure instead of classes (this is my terminology and english is not my language so I hope you understand what I'm on about...).
5
1961
by: blah, blah, blah | last post by:
I'm developing a .Net web application and created many helper classes often using static (shared in VB.Net) methods. Do I need to use the lock (SyncLock) statement in these methods to prevent multiple web application threads from using the same method at the same time? For example, I have a static method that extracts information from a page request cookie for use by other parts of the application. Since this happens on every request I...
4
2052
by: Joe Fallon | last post by:
In another post Kevin Spencer stated: "one should be careful of using static fields, properties, and methods, by understanding what the implications of such are (e.g. locking static variables when changing because they are not thread-safe)." Can someone please elaborate on the pros and cons of using static methods? (In VB they are called Shared methods.) The MS DAAB uses Shared methods. This means that all Data Access calls go through...
6
1459
by: Simon Harvey | last post by:
Hi all, In my project I have made a number of helper methods static. As I understand it, this will create the problem that multiple threads could access the static method at the same time and interfere with one another. My question is, for each static method, do I need to lock access to only one call at a time? I've noticed that Microsofts Data Application block also uses static methods for its data access calls - for example execute...
6
1775
by: MSDNAndi | last post by:
Hi, I have a baseclass (non-static) with some static and some non-static methods/fields/properties. In the baseclass in one of the static methods I need to do something like " somelogic .... CallToStaticMethod();
1
3098
by: sandyw | last post by:
I having trouble with my project and need a little help please "The method inputEmployee cannot be declared static; static methods can only be declared in a static or top level type" Part of my code where the problem is occurring. public class Employee { static ArrayList<Employee> arlist; int empid = arlist.size(); /** * displayMatch inputs a keyword from the user. It then iterates through the
0
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.