Code:using System; namespace ConsoleApplication { /// <summary> /// Summary description for Class1. /// </summary> class Class1 { static void Main(string[] args) { Console.WriteLine("Hello World"); } } }
Code:using System; namespace ConsoleApplication { /// <summary> /// Summary description for Class1. /// </summary> class Class1 { static void Main(string[] args) { Console.WriteLine("Hello World"); } } }
zen
public class ripoff{
public static void main(string[] args){
System.out.println("Does this look familiar?");
}
}
the HORROR!!
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
you have to do ALL THAT to make a simple hw app?
do you have to make it all into classes? like Java?
I like the old-fashioned C/C++ better
Oskilian
lol... Java, I'm sorry, but get your stuff together first and learn how to hide your data in classes... It does indeed look the same... a shame that C# manages to be the better implemented language, isn't it
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
> lol... Java, I'm sorry, but get your stuff together first and learn
> how to hide your data in classes...
How is their Java example 'not hiding data'? There is no data. It
is only a function call.
> It does indeed look the same... a shame that C# manages to
> be the better implemented language, isn't it
How is that better implemented?
Versus:Code:using System; class HelloWorld { public static void Main() { Console.WriteLine("Hello World!"); } }
They're exactly the same except we didn't have a 'using' (ie: 'import').Code:class HelloWorld { public static void main( String [] args ) { System.out.println( "Hello World" ); } }
Quzah.
I'm not talking about "Hello World".
Create class a;
Create class b, containing a private member of class a;
Grant public reading access ( a getA() function ) that
does not allow modifying private data, allows reading
it, and does not create a copy of the data, as that is
not an appropriate solution.
Try and cry.
I did implement examples in the last Java vs C++ thread...
Look them up if you don't want to do this yourself.
Oh, and an easy one: Create a constant object of class a.
( constant means only functions that do not modify class
data may be called )
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
C# is stupid. Why do this when there's java? How the heck do you even pronounce this language anyway?
It's pronounced "C sharp".
> Grant public reading access ( a getA() function ) that
> does not allow modifying private data, allows reading
> it, and does not create a copy of the data, as that is
> not an appropriate solution.
I hate to rain on your parade, but...
but, um... "What seems to be the problem officer?"Code:class ClassA { private int x; int getX( ) { return x; } } class ClassB extends ClassA { } public class MyProggie { public static void main( String[] args ) { ClassB B = new ClassB( ); System.out.println( "X = "+ B.getX( ) ); } }
Where's the problem? Please show me what it is I'm not upposed to be able to do here. I seem to be missing what you're saying I can't do. This is Java. This seems to do exactly what you're saying I can't do.
Quzah.
I don't know java that well, but I assume B.getX( ) in your println() call will create a temporary (a copy of private int x).This seems to do exactly what you're saying I can't do.
zen
I'm pretty sure that any time, in any language, when you use a "get" function, it returns the value, and thus, always makes a copy of it. The only way around that, would be to return a pointer to the actual variable. If you return a pointer to the actual variable, which I'd be surprised if it let you do, since it is protected, then that's the only way I can think it'd work.
In Java, pretty much everything is a pointer. If you could return a pointer to a protected or private variable, then it really isn't private any more. The whole point of something being private, is so that outside interference doesn't directly access the variable.
I imagine that if you were actually returning a pointer to the variable, then there would be some required additional overhead to limit access to the variable based on what class is using the variable and what not. In which case, that overhead would probably be (guessing) close to the same "overhead" you'd have by just creating a "copy".
A lot of speculation on my part, but it seems resonable.
Quzah.
Yes if you were returning a primitive, but if you were returning a user defined object then returning a pointer would be much more efficient (due to the size of object and the unnecessary copy constructor calls). C++ allows you to return a const reference (or const pointer) and I presume, as this discussion is taking place, that C# can do something similar -I imagine that if you were actually returning a pointer to the variable, then there would be some required additional overhead to limit access to the variable based on what class is using the variable and what not. In which case, that overhead would probably be (guessing) close to the same "overhead" you'd have by just creating a "copy".
Code:class a { private: int b; public: const int& get()const{return b;} void set(int _b){b=_b;} };
No copy of b will be made and you will not be able to change b without calling the set method (or cheating).
zen
>This is Java. This seems to do exactly what you're saying I can't do.
Um... please read my post again, it says EXACTLY what to do.
I was talking of class A and class B having a private member
of class A. In Java, you cannot return a reference to this
private ( NON-PRIMITIVE ) member, without giving write access
to your private parts ( ouch ). You can either return a reference,
which allows constructs like this:
MyVariable.GetMyPrivate().ChangeItsValue();
Which would change the private members value through a
read-only function. Or you can create a copy and return this,
so it can still be modified, but you don't have to care. But
creating a copy of an object ( imagine said object were
100 MB in size ! ) for each reading access to it is ridiculous.
Another, maybe easier thing: Create a class A. Create an instance of this class, that cannot be modified in the whole program. In C/C++/C# this is called a constant. In Java, you
have the final keyword, which is a joke, because only the
reference is final, not it's object. But then, how could the object
be final when you cannot define which methods change it and
which do not...
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.