|
it is not consider a good coding style by having 2 return. Declare a single variable that will elimanate 2 returns in your function
|
|
|
|
|
Arguable.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
You would need to use a ref or out keyword to make the first work, but that is rarely used in object oriented programming.
The second option is clearly the best option.
---
single minded; short sighted; long gone;
|
|
|
|
|
or
enum Result{Ok, Failure}<br />
<br />
public Result DoSomething()<br />
{<br />
...
<br />
if (everything is okay)<br />
return Result.Ok;<br />
else<br />
return result.Failure;<br />
}
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
Generally, the second option is the best (for many of the reasons already mentioned) and is what you should use most of the time. There are, however, times when passing parameters by reference is useful. For example, a function may need to return multiple values (this is often a sign that refactoring is in order, but there are legitimate examples of this need). Also, when passing a large value type by value, the type must be copied. This takes extra memory and cycles. Because of this, it may be acceptable (and even neccessary) at times to pass a large value type by reference.
Also, when passing parameters by reference, C# requires the 'out' or 'ref' keywords. Although they are compiled into identical IL, when using the 'out' keyword, it is expected that the method being called will initialize the value. When 'ref' is used, it is expected that the calling method will initialize the value.
So, while you won't usually need (or want) to pass by reference, there are times when it is appropriate.
Ian
|
|
|
|
|
Hi there !
I've getting in trouble using fileinfo.Delete() method in C#.
When I attempt to use it I got the message :
"The process cannot access the file 'foo.txt' because it is being used by another process."
How can I delete it ?
Thanks in advance.
|
|
|
|
|
You can't you just have to wait (or kill) until the process which is accessing the file.
|
|
|
|
|
Hi,
deleting a file immediately is very hard, for one you need sole access, which you
can not easily obtain. There are lots of programs trying to read the files you are
working with, such as AntiVirus tools, desktop search tools, etc. As a net result
a program that creates a temporary file often fails in deleting it when done with it !!
That is why Windows Explorer tacitly tries up to 5 times (with 1 second interval)
to delete a file when instructed to do so, before reporting failure.
My FileDelete() method does the same; most often it succeeds in those 5 seconds.
|
|
|
|
|
Convert.ToInt32(object);
I'm listening but I only speak GEEK.
|
|
|
|
|
Hello AreJay
Thanx for the reply. I have looked into that and I realised I have the options of Int16, Int32, and Int64. Could you be kind enough to tell me what is the diffences in these and does it make any difference which one I chose.
I have chosen Int32 and everything works fine.
Thanx for your help, mate.
Khoramdin
|
|
|
|
|
Khoramdin wrote: Int16, Int32, and Int64. Could you be kind enough to tell me what is the diffences in these and does it make any difference which one I chose.
Different sizes of integer. Int16 uses 16 bits to represent a number. Therefore you can store a number between -32768 and +32767. Int32 (synonymous with int ) uses 32 bits for a range of -2billion to +2billion (approx). Int64 uses 64 bits.
|
|
|
|
|
Hi,
I would like to know if some component vendors have a DateTimePicker replacement. I don't mean a calendar or any complex component, just a DateTime picker. Optimally it would add what lacks to the microsoft control, like changing the Culture, accepting null values, text formatting, custom fields (like what is available with the win32 control) and so on (I am aware of the free components showcased here at CP). Thank you
|
|
|
|
|
Hi,
I'm new in here.
I want to send a wav file through a socket in C#. The socket works fine, text can be send through it. How can I send a file in "parts" over the network. For example a file of 100kb must be send in parts of 4kb (25 * 4kb). On the other side of the socket, it will be stored in a buffer and it will be played.
Or is there another method to send audio?
A detail: the software is running on WinCE. (some parts of the code may be different from C# for WinXP)
Thanks in advance.
|
|
|
|
|
The most important part of streaming data over the network is to remember to use:
System.Net.IPAddress.NetworkToHostOrder
and
System.Net.IPAddress.HostToNetworkOrder
If you are using a TcpIp socket don't send in parts, the nagle algorithm is very efficient. However, on the receiving end you can choose which chunks to use and when.
If order is not important, speed is paramount, and only 4kb at a time use Udp datagrams.
File Not Found
|
|
|
|
|
Tnx,
I've read about the nagle algorithm... and yes I'm using a TCPIP socket.
I'm trying to implement it.
If there is something not working I'll post it.
Thanks.
|
|
|
|
|
Greetings,
I'm currently working on a C# application which interacts with data in an Access DB containing 2 tables. One table has 56 columns which I store related ID's in corresponding to the second table. These ID's are of the Text type and I have set the size field to 255 which is the maximum allowed text field in Access. The trouble is when I go to call the DataAdapter Update command passing it a dataset, after the update successfully updates 16 of the columns the 17th fails and says "Record too large". I have verified that the data in this column is exactly the same size as the others, 251 bytes, and also that it does not matter which column is the 17th to be updated I always recieve this error; i.e. even if the 17th column to be updated is actually the 24th in the database the error still occurs. I am not using the CommandBuilder object because I have had problems with the default optimitic concurrency creating an SQL Update Command that is too large for Access, it has too many AND parameters.
At first I believed it to be a problem with the amount of data that I am updating with one single update call so I split the UpdateCommand into 4 different Commands, updated using the first update command, set the rows in the dataset to modified, changed the update command to the second one, etc...
This is how I determined that it is always the 17th column to be updated. If I have 16 columns in the first update command the first successfully completes and the error occurs in the second. However if I have 17 in the first the error occurs there. Any help appreciated and I will clarify and confusion or questions that you have.
Thank you for your time,
Blake M. Ward
-- modified at 13:31 Monday 5th March, 2007
|
|
|
|
|
It's not the update query that is the problem, but how much data you put in the database record.
Access has a limitation on the size of a data record. In Access 97 and Access 2000 it is 2048 bytes, but it seems that it has been increased to 4096 bytes.
If you want to put more data than that in a record, use the Memo data type. The actual data is stored outside of the record so you don't have to worry about the record size, and there is no size limit on the field. The entire database is limited to 2 GB, though, and each table is limited to 1 GB.
---
single minded; short sighted; long gone;
|
|
|
|
|
Thank you for the response and information. It seems unfortunate that the database is limited at 2GB with a 1GB table limit but since that is what I have to work with it'll have to do. I will work on changing to the memo type.
Thanks again for your time,
Blake M. Ward
|
|
|
|
|
Hi,
I've Microsoft .Net Framework SDK v 2.0 . I've downloaded some demo projects from codeprojects. But when i want to setup project it says that i need .Net Framework 1.1.4322 Is there any way to setup those projects in the current version of .Net ?
001
|
|
|
|
|
Just recompile them, the framework is backwards compatible.
|
|
|
|
|
How can i compile a windows installer package?? (I've only demo project, no source code)
001
|
|
|
|
|
The source code is hidden by the designers, you can build it by right clicking the project and selecting build from the Solution Explorer.
|
|
|
|
|
How is it possible to build an array of a generic type collection?
For example this is what I am to populate the ForwardCurves generic collection.
Notice that this is ok for the first loop.
For the following loops I wouls like to add to this generic collection i.e. ForwardCurves but would like to identify each loop separately in the generic collection.
Something like:
ForwardCurves[i].Add(forward);
Is this possible?
Thanks
Thsi is what I am doing now but you can not identify each table loop in the generic collection.
List<forward> ForwardCurves = new List<forward>();
foreach (DataRow row in table.Rows)
{
Forward forward = new Forward();
forward.IndexID = row["IndexID"].ToString();
ForwardCurves.Add(forward);
}
|
|
|
|
|
arkiboys wrote: Is this possible?
Yes
led mike
|
|
|
|
|