• What do you need help with? Version 1
    5,001 replies, posted
Is there a reason why some people create two functions to set and get a private variable of a class rather than just putting that variable in public and accessing it directly? Is it so you can potentially control what you can set that variable to?
It has something to do with encapsulation. The potential user doesn't need to know how the variable is set or returned, or even how it's called. He may know how the function to set it is called but he doesn't know the variable name or what exactly the function does.
Yes, and also so that you have the flexibility to remove the variable later, storing the data in a different way, just by rewriting those two functions. If other things were accessing the variable directly, the change would be much more difficult.
How do I check input for a C# console application? Like if I type something and press enter, something else happens.
daaaaarrrrrpppp [code]Console.ReadLine()[/code]
I mean CHECK INPUT. As in "If I type "Hello" it types back "Hello" " but not necessarily. I already knew about Console.ReadLine(). I mean something like if(Console.Input="Hello") //yada yada.
[QUOTE=Chad Mobile;21045837]I mean CHECK INPUT. As in "If I type "Hello" it types back "Hello" " but not necessarily. I already knew about Console.ReadLine(). I mean something like if(Console.Input="Hello") //yada yada.[/QUOTE] use your brain, i don't even know c# and i think it's obvious that you use that console.readline magical power and then you store it in a variable or maybe you can even do if ( Console.ReadLine() == "Hello" )...
I already tried that. " Cannot implicitly convert type 'string' to 'bool'. "
[img]http://www.goatse.fr/hello.jpg[/img]
wtf...... MODS BAN HIM!!!
He got banned for a Ban-Me instead. Damn.
[QUOTE=Chad Mobile;21046134]I already tried that. " Cannot implicitly convert type 'string' to 'bool'. "[/QUOTE] Dunno why it says that. Now, that I don't code in C# and all.. I don't have a clue. But are you missing two ='s by any chance? Console.ReadLine() returns a string, and "hello" is a string, as far as I am aware...! I can't see why either would be getting converted to a bool. [code] if ( Console.ReadLine() == "Hello" ) { // Do some fancy shit } [/code] Edit: Just fired up a C# project, you forgot an extra "=". When you do "variable = "hello"", you're assigning a value to a variable. When you do "if ( variable == "hello" )" you're testing for equality.
Also tried that. Operator '==' cannot be applied to operands of type 'method group' and 'string'. [editline]01:37AM[/editline] Oh, nevermind. I forgot the (). Thank you :smile:
[QUOTE=Chad Mobile;21046522]Also tried that. Operator '==' cannot be applied to operands of type 'method group' and 'string'. [editline]01:37AM[/editline] Oh, nevermind. I forgot the (). Thank you :smile:[/QUOTE] No worries. You should invest in a book in whatever language you wish to follow.
Can't really buy a book anywhere, but I'm reading tutorials :smile:
[QUOTE=Chad Mobile;21046595]Can't really buy a book anywhere, but I'm reading tutorials :smile:[/QUOTE] [url]www.amazon.co.uk[/url] :)
No credit card(s) or any forms of internet payment ):
[QUOTE=Chad Mobile;21046686]No credit card(s) or any forms of internet payment ):[/QUOTE] [url]http://lmgtfy.com/?q=prepaid+credit+card[/url]
There aren't any available in my area :frown:
[QUOTE=Chad Mobile;21046796]There aren't any available in my area :frown:[/QUOTE] Where do you live?
I'd rather not give that out. :smile:
In XNA/C#, what does the f mean that is attached to numbers? Like when scaling something, one might put 1.0f. What does the f do?
[QUOTE=Teap;21046948]In XNA/C#, what does the f mean that is attached to numbers? Like when scaling something, one might put 1.0f. What does the f do?[/QUOTE] It declares it as a floating point number, instead of say.. a double; 1.0 == double, 1.0f == floating point number
True, but misleading: a double is also a floating-point number. The "f" signifies the data type named "float" (single-precision floating-point); without it you get the data type named "double" (double-precision floating-point).
In java, how do I set the width and height of a graphics window? I'm using netbeans. Also still importing from acm's since I'm learning.
[QUOTE=tanthreecle;21054492]In java, how do I set the width and height of a graphics window? I'm using netbeans. Also still importing from acm's since I'm learning.[/QUOTE] graphicsWindow.setSize(size);
[QUOTE=Robber;21054979]graphicsWindow.setSize(size);[/QUOTE] [img]http://i39.tinypic.com/2m6tvg1.jpg[/img] cannot find symbol [b]Edit:[/b] Guys stop rating me funny I'm super srs
So, I made a class in XNA, I have static variable spriteBatch and a static function init that takes SpriteBatch sb as an argument. In Game1.cs I call the init function like Asdf.Init(spriteBatch) and the init function sets spriteBatch (the static var) to sb. I'm not sure but i think that it's only a reference. It might not matter tho. Then I have a static method draw on my class that starts with spriteBatch.Begin() but it throws an exception Object reference not set to the instance of the object I think is has something to do with the varibales and/or methods being static since almost the same thing works on another project that passes spriteBatch as an argument to the constructor when instancing that class. Any ideas how I might fix this? P.S. Are there special code tags for sharp highlighting?
Okay, my window issue still isn't fixed. I really need help with this: [code]#include <windows.h> LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX windowClass; HWND hwnd; MSG msg; bool done; windowClass.cbSize = sizeof(WNDCLASSEX); windowClass.style = CS_HREDRAW | CS_VREDRAW; windowClass.lpfnWndProc = WndProc; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = hInstance; windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); windowClass.lpszMenuName = NULL; windowClass.lpszClassName = "MyClass"; windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); /* Register window class*/ if (!RegisterClassEx(&windowClass)) { return 0; } /* Class registerd, so now create window*/ hwnd = CreateWindowEx(NULL, //extended style "MyClass", //class name "Archy's Program", //app name WS_OVERLAPPEDWINDOW | //window style WS_VISIBLE | WS_SYSMENU, 100,100, //x/y coords 1024,768, //width,height NULL, //handle to parent NULL, //handle to menu hInstance, //application instance NULL); //no extra parameter's /* Check if window creation failed*/ if (!hwnd) { return 0; } done = false; while(done = false) { GetMessage(&msg,hwnd,NULL,NULL); if (msg.message == WM_QUIT) //check for a quit message { done = true; //if found, quit app } else { /* Translate and dispatch to event queue*/ TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_QUIT: PostQuitMessage(0); return 0; } return (DefWindowProc(hwnd,message,wParam,lParam)); } [/code]
[QUOTE=Darwin226;21063659]P.S. Are there special code tags for sharp highlighting?[/QUOTE] just use [cpp], it's good enough
Sorry, you need to Log In to post a reply to this thread.