|
-
Dec 19th, 2007, 07:04 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2.0] Optional Parameters
I believe it is possible to have optional parameters in C#. Some programmers will swear by overloading constructors, but in my eyes, less code is easier to understand and just better for me.
I am aware that there is a question mark.. I guess I would call it.. an operator?
You can put it after types in variable declarations and stuff of the sort. For example:
Code:
private Rectangle? sourceRectangle;
public SpriteToRender(Rectangle? sourceRectangle)
{
this.sourceRectangle = sourceRectangle;
}
Anyways, that's how I believe it works. I find it rather redundant to create an overload of the constructor multiple times when you can just use the "?" (operator?)
Anyways, try searching for a "?" on google or msdn. I can't really find any documentation on it! Can anyone explain this (operator?) to me? Is it good to use? My friend who is a game programmer for exDream and Microsoft for a couple projects uses them a lot. Since I know he is a great programmer, I wanted to learn these for myself. Are they good practice? Am I better off just overloading the constructor instead of using these? Are they the equivalent to the "Optional" keyword in VB?
Thanks a bunch.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|