Okay so about a year ago I took a usual college class on C# and since have been addicted to the language, I love writting in it. But I have been puzzled by an issue that I have never figured out, and I decided it's finally time to ask for some help.
Okay so call me a noob, but I have no clue what the purpose is for 'static' when it comes to programming (yeah I know sad), and that has to deal with the issue I am having. I learned about delegates from my class (which I think are awesome by the way). But for some reason when ever I call a class from a Form class I have to add a bunch of the word static into the code. Here's an example, of what I have to do to call a class from a Form class (sorry if this look weird I copied it from a code I have in the works, where I finally had to ask about this)
//----------------------------------------------------------------
namespace PeriodicTable1v3
{
public delegate object [,] readInFile();
}
//----------------------------------------------------------------
namespace PeriodicTable1v3
{
public partial class Form1 : Form
{
static readInFile readInFileCall = new readInFile(readInExcel1.readInFile);
//had to add static here
object [,] values = readInFileCall();
//....bunch of code
}
//... bunch of code
}
//----------------------------------------------------------------
namespace PeriodicTable1v3
{
public class readInExcel1
{
static Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
//had to add static here (a variable I use both method in this class)
public static object [,] readInFile ()
{
//had to add static here
//...bunch of code
values = gatherInfo(excelFile);
//...bunch of code
}
public static object [,] gatherInfo (Workbook excelFile)
{
//had to static here
//...bunch of code
}
//----------------------------------------------------------------
I hope this makes sense, this is an actual code (now granted I just added the statics for the example, but I know that I have to do this to make it work). Hopefully this small version works, cause the full version is over 500 lines of code.
This is something that has bugged me for along time and I finally decided I need to ask for some help (also if someone would enlighten me why I use 'static' period, as I have never understood what it's for, again I know that seems like a stupid thing to say but it's the truth, i only use it if the program won't compile until I add it)