|
There is nothing like optional parameter in C#.
Time is the best teacher; unfortunately it kills all of its students.
जय हिंद
|
|
|
|
|
Not until C# 4, at least.
(Oook, DaveyM69 posted the same thing at the same time... )
|
|
|
|
|
Can't do that until C# 4.0 which hasn't been released yet.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
this means, i should go with an overloaded function, that's it?!
|
|
|
|
|
If there is not anything that stops you from adding another overload (such as conflicting signature with another overload), yes.
Alternatively, you can mimic an optional parameter by addin a parameter that accepts null values, and using a default value in the method body if null has been received.
|
|
|
|
|
In reference to C# 4.0, I was just curious, would it be possible to know if an optional parameter was passed or no ? If we did not pass the value, it would take the default value which is defined. But how will the body know if the optional parameter was passed or no ?
|
|
|
|
|
Well, it will not know. It will use the default value without worring if it was passed by the caller or automatically used.
The whole point of optional parameters is to make that logic transparent to the method implementation.
|
|
|
|
|
Well, I understand that. Looking at the OP's question and the given reference to C# 4.0 Optional parameters, made me curious.
|
|
|
|
|
Hi
Any body help me
I am new in MVC design pattern. i want call one main form to
another form using MVC design pattern, How can handle the Model view
control object. Please give some article path about this.
Thank you
|
|
|
|
|
|
|
Before using MVC it should be clear concept of model view controllar..
For best practic you must read MVC patterns then implement.
Naresh Prakash
|
|
|
|
|
i want to aply client side validation on the gridview for that i want to retrive the values of template checkbox of gridview how i can get the values of check boxes in a java script function
|
|
|
|
|
I have a generic list List<classname> and I want to pass it to another method which does not know the type of the list. I have tried List<object> to no avail
<br />
private void GetList()<br />
{<br />
List<clsproduct> Products = oProd.GetRecordList(-1);<br />
lvLoadList(lvProd,Products)<br />
}<br />
<br />
private void lvLoadList(ListView oLV, List<object> oList)<br />
{<br />
}<br />
</object></clsproduct>
This code that fails with invalid argument
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: which does not know the type of the list
Then you can make that method generic.
private void lvLoadList<T>(ListView oLV,List<T> list)
{
....
} Now you can write
List<Product> Products = oProd.GetRecordList(-1);
lvLoadList<Product>(lvProd,Products) Mycroft Holmes wrote: This code that fails with invalid argument
Because List<Product> is not List<object>
|
|
|
|
|
N a v a n e e t h wrote: Because List<product> is not List<object>
You've confused me there. Product is an Object . Everything is an Object (well nearly everything ).
Of course Object is not a Product . Is that what you meant?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: Product is an Object. Everything is an Object (well nearly everything Smile ).
Of course Object is not a Product. Is that what you meant?
No. List<Product> is not List<object> . List<Product> is a collection of products and List<object> is collection of objects. I mean, both will be considered as different types even though product is derived from object.
Still confusing?
|
|
|
|
|
N a v a n e e t h wrote: Still confusing
No.
The light-bulb came on a split second after I hit the post message button. I was too embarrassed to modify the post.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
For more information on how generics works on .NET, check this[^].
|
|
|
|
|
Covariant interfaces in C# 4.0 attempt to address this problem - you can write IEnumerable<object> v = new List<string>();
Regards
Senthil [MVP - Visual C#]
_____________________________
My Home Page |My Blog | My Articles | My Flickr | WinMacro
|
|
|
|
|
Yeah that's cool. I forgot that
|
|
|
|
|
Thanks Navaneeth, I now have a generic listview loader from a List<t>. Not sure of the benifits of generics over datatables yet but working on em!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: Not sure of the benifits of generics over datatables
Type safety. That's the biggest advantage.
|
|
|
|
|
Hah you're talking to an ex VB dev here, type safety indeed.....
Everythings a variant, that's theway to go.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi All,
I am currently developing a program in VS 2005 C#.
In the program, it shows a live video on a sequence of IO (cylinders, sensors) actions.
The live video is being displaying with a PaintDelegate thread and a callback that I copied from the sample program of the frame grabber manufacturer.
And the sequence of IO is being performed with a backGroundWorker, in which the sequence repeats for 5 times with a for loop.
After leaving the program to run for more than 24 hours, it is noticed that the live video will freeze. After checking with the frame grabber manufacturer, I was told that their sample program should have no problem to run a non-stop live video for 24/7.
So now, I am kind of suspecting that it is the problem with the backGroundWorker, with its resources keep accumulating until it occupies the whole memory of the CPU.
In this case, how should I solve this problem? Should I do a backgroundWorker.Dispose();
every time?
The tool tip on backgroundWorker.Dispose(); says that it releases all resources used by the System.ComponentModel.Component.
What does it means by all resources? Are the boolean type flags considered as the resources too?
If the boolean type flags are released, what state will they become after the .Dispose()?
|
|
|
|