c# - Instantiating an object of one class in another -



c# - Instantiating an object of one class in another -

could 1 allow me know how instantiate , object within class in c#.

the first 3 string variables here (secureid, emailaddress , phonenum) place them in class , assign values them in class. in c++ utilize friend class, couldn't find c#.

further clarification:

i take code:

static string secureid; static string emailaddress; static string phonenum;

and place in it's own class. lets phone call public class mymsg. instanitate mymsg in below class programme , able assign values fields such mymsg.secureid = strdataparse[0]. having issues accessing mymsg fields through class program. hope helps.

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.net; using system.net.sockets; namespace emailsmssocketapp { class programme { static string secureid; static string emailaddress; static string phonenum; static byte[] buffer { get; set; } static socket _socket; static void main(string[] args) { _socket = new socket(addressfamily.internetwork, sockettype.stream, protocoltype.tcp); _socket.bind(new ipendpoint(ipaddress.any, 1234)); _socket.listen(100); socket accepted = _socket.accept(); buffer = new byte[accepted.sendbuffersize]; int bytesread = accepted.receive(buffer); byte[] formatted = new byte[bytesread]; (int = 0; < bytesread; i++) { formatted[i] = buffer[i]; } string strdata = encoding.ascii.getstring(formatted); //console.write(strdata + " ascii strdata" + "\r\n"); string[] strdataparse = strdata.split(','); foreach (string word in strdataparse) { // console.writeline(word); secureid = strdataparse[0]; emailaddress = strdataparse[1]; phonenum = strdataparse[2]; }; console.writeline(secureid + " outside loop"); console.writeline(emailaddress + " outside loop"); console.writeline(phonenum + " outside loop"); console.read(); _socket.close(); accepted.close(); } } }

classes , members private default. need mark class , members public or internal visible outside of class.

you right there no friend classes in c# although there nested types (classes defined within other classes).

why c# not provide c++ style 'friend' keyword?

the comment above access program.secureid right if public or internal , mutual practice create field property although not necessary.

c# .net class methods

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -