Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a class?

Status
Not open for further replies.

A1METALHEAD

Programmer
May 21, 2004
76
US
well, i know c++, and i was wondering if it is possable to make a class obusly this:

class aClass
{
public:
aClass(int iniInt){ theInt=iniInt; }
aClass(){ theInt=10; }

int getInt(){ return theInt; }
void changeInt(int newInt){ theInt=newInt; }
private:
int theInt;
};

wont work, nomatter where i put it. i have tryed sustiting the

Public:
bla bla bla

with a public before each method, but that still dosent work. is there anyway to make a class in c sharp?
 
First remove the ; at the end of the class declaration. It's no longer needed. As for the public:/private: I know it's no longer needed and possible no longer even legal. You would want to write it loike this:

class aClass
{

public aClass(int iniInt){ theInt=iniInt; }
public aClass(){ theInt=10; }

public int getInt(){ return theInt; }
public void changeInt(int newInt){ theInt=newInt; }

private int theInt;
}
 
now how do you create a object of that class and use it? i have some trouble doing:

aClass test();
test.changeInt(int.Pasres(textBox1.text));
label1.text=test.getInt().ToString();
 
ok, i figured it out, thanks! also one more question, how do you connect two progams over the internet, so they can send info between each other?
 
You instantiate objects in c# like in java. Actually, since you are a c++ guy, it's like defining a pointer to an object then instantiating the object by creating a new one. Here is an example:

C#/Java

SomeClass objMyObject = new SomceClass("someargs");

Which is pretty much equivalent to c++:

C++:
SomeClass *pobjMyObject;
pobjMyObject = new SomeClass("Blah");
 
There are a couple of ways but the most common approach is by using sockets. Check out System.net.sockets for not only the socket class itself but the TcpClient class which is really quite useful. Luckily, c# seems to abstract away :) most of the underlying stuff needed for socket programming so you don't really have to worry with it all that much if you just want to connect, send some data, etc. And if you get board, check out c# Xml object serialization so you can send objects over the socket. Serialization isn't anything new and neither is Xml serialization, but I really like C#s implementation of it.
 
yha, im making a instant messanger. sending an between eachother is what i wanted to do. so thanks for all the help you gave me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top