473,473 Members | 2,144 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Non Static Members

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
Nov 16 '05 #1
3 1678
Problem is not very clear from this code segment. But you can try changing
texbox property "modifier" "Protected"
-Praveen

"Richard" wrote:
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

Nov 16 '05 #2
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?
Nov 16 '05 #3
Richard <di*********@yahoo.co.uk> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

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

Similar topics

3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
15
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
6
by: lovecreatesbeauty | last post by:
Hello Experts, Why static data members can be declared as the type of class which it belongs to? Inside a class, non-static data members such as pointers and references can be declared as...
13
by: Adam H. Peterson | last post by:
I just made an observation and I wondered if it's generally known (or if I'm missing something). My observation is that static protected members are essentially useless, only a hint to the user. ...
3
by: Mauzi | last post by:
hi, this may sound odd and noob like, but what is the 'big' difference between static and non-static funcitons ? is there any performace differnce? what is the best way to use them ? thnx ...
6
by: Matt | last post by:
All of a sudden all my C# apps require the keyword static on all global fields and methods that I create. Even in the simplest of console apps. Can someone tell me what I have inadvertenly set in...
11
by: dee | last post by:
OleDbCommand class like many .NET classes has the following description in its help file: "Thread Safety Any public static (Shared in Visual Basic) members of this type are safe for...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
8
by: crjjrc | last post by:
Hi, I've got a base class and some derived classes that look something like this: class Base { public: int getType() { return type; } private: static const int type = 0; };
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.