custom class library as an array C# -


i'm working class library in c# own methods , want create array library, when call in main program cant see methods.

public class classlibrary1 {     public int num;                             public classlibrary1 ()     {      }      public void readdata()     {          console.write("write number ");         num = int.parse(console.readline());     } } 

program.cs :

classlibrary1[] arraynumbers = new classlibrary1[5];  arraynumbers.readdata(); 

and can't use readdata().

can me?

if want call methods in class, you'll have create @ least 1 instance. is, you've done create array of null references, , attempt call method on array. here's 1 way it.

classlibrary1[] arraynumbers = new classlibrary1[5]; for(int = 0; < 5; i++)  {     arraynumbers[i] = new classlibrary1(); } arraynumbers[0].readdata(); 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -