is it possible to have global level methods in c#? I have several forms and they are going to use roughly similar logic. i can design methods which can work with them all depending on what parameters are passed to them but how do i make these methods global so that all the forms can access them?

for example. one method retrieve data from a database one field and record at a time. two forms need to use it. but i only know how to create methods that can be accessed by one form. this i do by placing the method within the class curly brackets of the form. but how do i make such a method accessible to both forms?

Recommended Answers

All 2 Replies

you can create a seperate class, then use it in your forms...
for example

public class myDBAccess {
   public string getFoo() {
      //your db access logic
   }
}

then you can use it like this...

myDBAccess dba = new myDBAccess();
textBox1.text = dba.getFoo();

thanks. it works. i do not know why i did not think of that myself. probably tunnel vision!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.