|
Use the minimum syntax necessary to achieve readbility. IMHO, an arbitray parameter list is less documenting. Of course by the same token, which one looks cleaner
Foobar(this.foo);
or
Foobar(this.foo[0], this.foo[1], this.foo[2]);
Really I wouldn't fault you for using Params I just don't prefer it.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: Foobar(this.foo);
That will work for the param keyword too. Test it, you can pass an array instead of the optional params.
|
|
|
|
|
I have to agree with leppie, I don't see the clarity argument either. The programmer can use both styles of calling.
Wout
|
|
|
|
|
There is a small speed penalty, but else its just a 'compiler macro' like foreach (not really, its a bit more internal).
wout de zeeuw wrote: public Polyline4D(params Vector4D points) { }
params Vector4D[] points <-- note the array.
|
|
|
|
|
Ah, sorry, forgot the array thing yes (I'll mod the post and erase my traces ).
Would there be a runtime penalty? I would have guessed that just the compiler would insert a new Vector4D[] { a, b, c } statement, which the programmer would otherwise have to do manually.
Thanks,
Wout
|
|
|
|
|
wout de zeeuw wrote: I would have guessed that just the compiler would insert a new Vector4D[] { a, b, c } statement, which the programmer would otherwise have to do manually.
Not even. I am not sure what exactly what causes the penalty, as seen thru a profiler, but I suspect it needs to do a type check on the 1st params parameter, exactly for the array case.
Regarding your other question: not all languages support the params keyword. And in the case of AddRange() will cause a method resolution conflict possibly.
|
|
|
|
|
leppie wrote: Not even.
Hmmm, when I look in Reflector to see the disassembled code I see code like the following:
<br />
pointdArray1 = new Point3D[] { pointd3, pointd1, pointd2, pointd4 };<br />
polylined2 = new Polyline3D(pointdArray1);<br />
So that makes me think that apart from the syntax it's the same as not using the params keyword.
Not all languages can define params parameters, but that set of languages is probably not the same as the set of languages that can use those methods probably? To me the latter is only important.
Wout
|
|
|
|
|
I recently started wrting C# and I was curious to know what was the difference between validators and exception statements. I was wondering when and why use a Try...Throw statement as in contrast to a field/control validator. Don't both these feature do the same thing? Ensure that the correct variables are being inputted into the application. This is why the question the begs to be answered is when do u use a validator and when do u use a try..throw exception?
Greg
The Belizean Dan Dada!!!
|
|
|
|
|
I personally use try/throw when making a call to the SQL server. I have a program that inserts into a database. If the insert fails, then I use the catch to dump an error message.
When using plain old vanilla fields validators work just fine.
I don't know if one has more overhead that the other; that may be a consideration as well.
|
|
|
|
|
Hello
Exceptions were neatly described by a known programmer as "Expecting the unexpected" -unfortunately I don't seem to remember his name at the moment-.
The more your code is advanced or complicated, or doing hardware related tasks for example, the more error brone your code gets. Sometimes you write a long method to calculate some value, and in the middle you find yourself dividing by zero- for example-. Or accessing an access denied resource, unexpectedly deleted file, wrong or unavailable adress, etc...
Examples of exceptions are by far more than what a simple post can count. There are literallt thousands of cases in which you can benefit from putting your code in a try block. Yet that will be at the cost of excuting time. The more try block, the slower your program gets. While a simple validation methods only handles the user input.
The throw statement is appropriate when you want to put the error handling on the shoulder of a lower method in the call stack. ie. You don't want to handle the code in the current method, instead throw it back to the calling code.
To summerize:
Validation is concerned mainly with user input, to save the time that would be consumed by exception catching. While in other situation when you don't know what might go wrong -yet sometimes you might expect, or have a kind of an idea-, then it would be wise to put your code in a try block to prevent your program from crashing.
Regards
|
|
|
|
|
This makes a whole lot of sense. In essence a try...throw would be best used for a derived value while validators are use to ensure that those braineless users can not input flakey data.
Greg
The Belizean Dan Dada!!!
|
|
|
|
|
Hello development community, I have a communication problem with two applications (client & server) I'm developing. The frase is "event notification". I have a client application that connects to a server application to subscribe to an event, for example, my server app. has a list of sales being made through out the day, so it's constantly recievine data from the sellers, and supose the client app. wants to be notified when a certain sale from a certain seller is made, so the client could be waiting for a few minutes until the data is available on the server and can be notified.
But wait there's more, there's a high probability the client is behind a firewall and in a private network, I don't know if the solution is affected by this.
Maybe this example is absurd, but my application needs to do something like this. Like MSN Messenger, you connect and wait for a friend to send you something. In my case they aren't string messages, they're objects from the buissnes model. I need to know how to do it, what do I need and a little orientation on using or mixing the tools.
I've been reading books on .NET Remoting, Web Services and Sockets, in search for an answer, but haven't been succesfull.
Maybe its simple and it just hasn't hit me or maybe it is a little elaborate to do.
Thank you.
|
|
|
|
|
Client registers to your webservice indicating that it would like to revieve event notification.
Your application will then call a webservice on the clients end when that event occurs.
It would be fairly trivial to implement.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Ing. Pedro Fernandez wrote: the client is behind a firewall and in a private network, I don't know if the solution is affected by this.
A firewall can affect anything you want. A typical implementation of a firewall would normally block the servers attempt to connect to the client that is behind the firewall as in the Web Service approach that Ennis suggested.
Using a nailed up connection over port 80 would be about the only way to accomplish this thru a typical firewall configuration and even with that the admin could still block your servers domain.
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
Hi everybody
i am going to develop a telephone system project or it seems to me like that
the problem is:
we allready have something like a switch but the problem is that switch maximum have five ports only we want to develop a desktop program that we just buy one telephone line from the telecomunication company and seperate this one line to more than five telephone cabin that can used in the same time and count the time the call take in order to count the many that the calls cost.
my Q. is is this available in C# or any other language to deal with that and how ?
thank you for helping me
yours
|
|
|
|
|
And some $300 hardware.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
a computrized system that control the telephone ?
|
|
|
|
|
Can you do it with the existing phone system you have? No, I seriously doubt it. Do you homework on how the phone systems REALLY work, then you can start thinking about this project.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hello ystar,
Do u hear about Asterisk open-source PBX(Click Here). Which can provide u a complete telephone exchage & also comunicate with telephone line.
But to connect with telephone line u have to purchase FXO card or other hardware that supported by asterisk.
Asterisk is only for Linux. U can make soft phone or just purchase it. And if u want to use existing telephone then u have to purchase Cisco Linksys hardware(Find Here).
Now by using Astrisk u can controll all things by ur computer.
regards,
Divyang Mithaiwala
System Engineer & Software Developer
|
|
|
|
|
A co-worker of mine is having trouble with his C#. Unfortunately, I don't deal with C# all too much so I'm not entirely sure where the error is taking place.
He's having trouble with a line of code used to create a Crystal Report. He's trying to call the .ExportOptions property of the ReportClass object, however for some reason, visual studio isn't even providing the dropdown to access the different ReportClass properties. It's not recognizing repClass as a ReportClass variable. Any idea why?
-------------------------------------------------------------------
public partial class _Default : System.Web.UI.Page
{
private static Data_PSPP oData_PSPP;
private string sID = "";
private ReportClass repClass = new ReportClass();
protected void Page_Load(object sender, EventArgs e)
{
DataTable dtSource = new DataTable();
oData_PSPP = new Data_PSPP();
this.sID = Session["ProjectID"].ToString();
if (!IsPostBack)
{
ExportOptions objExportOptions = new ExportOptions();
DiskFileDestinationOptions objDiskFileDestinationOpions = new DiskFileDestinationOptions();
string ExportFileName = "";
//Problem line.... "repClass" doesn't provide access to ".ExportOptions"
///////////////////////////////////////////////////////////////
objExportOptions = repClass.ExportOptions
//////////////////////////////////////////////////////////////
}
}
}
-----------------------------------------------------------
Thanks in advance.
-Goalie35
|
|
|
|
|
So, what exactly is the problem? Is the problem that IntelliSense isn't working? Is that all? Are you Is your colleague getting a compiler error?
:josh:
My WPF Blog[^]
|
|
|
|
|
He's getting a compiler error because for some reason, vs.net doesn't feel ".ExportOptions" is a valid property of ReportClass. Or at least a valid propery of the variable assigned the value of a ReportClass(the "repClass" variable)
This same code was implemented in VB.net and we had no problem, so it's a little odd.
Thanks again.
-Goalie35
|
|
|
|
|
Goalie35 wrote: He's getting a compiler error because for some reason
What does the compiler error say? What is the actual error message?
:josh:
My WPF Blog[^]
|
|
|
|
|
Hi,
The problem is that the reference for ReportClass is not set. For further info check
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspnetcustrep.asp
|
|
|
|
|
hi i m reading images from the databse and showing on picbox,so i had to make the temporary file to show pic on the picturebox thorugh Pic.image=Image.fromfile etc. it works fine.
i want to make one file for that purpose and delete when new file is readed from databse.
i m using this code for that purpose
Pic.image=null;
if(File.Exist("temp.bmp"))
File.Delete("temp.bmp");//give exception file used by process
String newf="temp.bmp"; and save the new data from database to this file and show it to the user.
but it give the exception that file is used by another process,i had clear the picbox but still gives.
how to do that Thanks in advance.
Tasleem Arif
|
|
|
|