Non Static Members

R

Richard

im fairly new to c# but im trying to display some text in a textbox and i
get the error

"Cant access nonstatic member from outer type "Server.Form1" via nested type
"Server.Form1.SocketPacket"

code: -
public class SocketPacket

{

public Socket thisSocket = null;

public byte[] byteBuffer = new byte[256];

public int id = 0;

private StringBuilder stringBuffer = new StringBuilder();

public void appendStringBuffer(string data)

{

this.stringBuffer.Append(data);

string text = this.stringBuffer.ToString();

int end = text.Length;

if(text.LastIndexOf('?') == text.Length)

{

addTextToConsole(text);

}

}

}

here's the function im trying to call :-

public void addTextToConsole(string text)

{

ConsoleTextBox.Text += text;

ConsoleTextBox.Text += "\r\n";

ConsoleTextBox.Select(ConsoleTextBox.Text.Length, 0);

ConsoleTextBox.ScrollToCaret();

}



thanks for anyhelp!

R.Adnams
 
G

Guest

Problem is not very clear from this code segment. But you can try changing
texbox property "modifier" "Protected"
-Praveen
 
R

Richard

That had no effect.

i think its complaining that the function addTextToConsole is not static but
when i make the function static i get even more errors.

is there another way to call non static functions?
 
J

Jon Skeet [C# MVP]

Richard said:
i think its complaining that the function addTextToConsole is not static but
when i make the function static i get even more errors.

is there another way to call non static functions?

You need to supply a reference to an instance of the outer class.
There's no implicit instance available to the nested class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top