|
Hi,
IMO a return value is the normal approach.
It has some drawbacks:
- you can return only one thing;
- if the return thingy is a reference type, then the API choice implies you must
create an object of that type, which you may or may not want to impose on the API users.
Hence, a ref parameter is acceptable and useful when:
- the function has to produce more than one thing;
- or the function is supposed to stuff some data in a pre-existing struct.
|
|
|
|
|
Thanks, answered my question succinctly.
this thing looks like it was written by an epileptic ferret
Dave Kreskowiak
|
|
|
|
|
In my opinion I'd use the non-ref method. The reason is, that many classes in the .NET framework are immutable, like string . Even more important, the DateTime class also uses return values (AddHours , AddMonths , etc.), which means that DateTime objects are immutable, too.
In C# 3.0 you could also use extension methods, for example like this:
public static class DateTimeExtensions
{
public static DateTime SetToHour(this DateTime source, int hours)
{
if ((hours < 0) || (hours > 23))
throw new ArgumentOutOfRangeException("Hours must be between 0 and 23");
return source.AddHours(hours - source.Hour);
}
}
and call it like that:
DateTime t = DateTime.Now;
Console.WriteLine(t);
t = t.SetToHour(24);
Console.WriteLine(t);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
>>The reason is, that many classes in the .NET framework are immutable, like string.
Im not quite getting in what way you mean that would affect anything?
Its perfectly possible to pass a "ref string"
Even if the instance of a string is immutable doesnt mean that the variable reference to that instance is immutable...
Or do you just mean that the api would be more standard because other methods on immutable types work that way?
(In that case I agree , rule of least surprise)
|
|
|
|
|
Roger Alsing wrote:
Its perfectly possible to pass a "ref string"
Even if the instance of a string is immutable doesnt mean that the variable reference to that instance is immutable...
Absolutely correct - what I meant is that the .NET library methods for the string and DateTime objects (among others) do not modify the variable but rather return a new instance. So if you want to add another method to the DateTime class (by using extension methods or simply a utility class) I might be a good idea to do it in the same way like the original DateTime methods do, by returning a new instance.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I developed a C# console program to control a camera's PTZ, and I call remote procedures from a GUI to move left/right/up/down. As I have 2 WindowsXP computers my C# RPC's work great. QUESTION: I also need to drive this PTZ from a computer running Windows, but the coding environment is JAVA. What does the JAVA coder need to do in order to call my functions? thanks, xlthim
|
|
|
|
|
Couple ways to do this. A popular one seems to be utilizing Mono's IKVM[^].
Life, family, faith: Give me a visit.
From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of."
Judah Himango
|
|
|
|
|
I am trying to use a DLL which was originaly written in fortran. Allthough this DLL is suposed to be in C, a lot of its functions do not work in C# (some does). I believe it has fortran version as well as C version. Has anyone played with Fortran DLL in C#. I get the following errors during compilation.
AccessViolationException
BadImageFormatException
DllNotFoundException
YOu can go to this link http://www.originlab.com/index.aspx?s=8&lm=117&pid=251[^]
download the "examples in zip form". They have a simple DLL,FortranDLL, which contains basic functions such as double SUMFT(double, double), which returns the sum of two doubles. Can any one make it work? What do i need to make it work?
|
|
|
|
|
I believe you can P/Invoke into most (all?) Fortran calls. Have you tried this? The Numerical Algorithms Group shows how to call their Fortran dll from C#[^], perhaps that will get you off to a good start.
If this fails or doesn't work for certain calls, but you can access it via C++, you could write a C++/CLI (managed C++) dll that talks to the Fortran dll, then have your C# code talk to the C++/CLI dll. There are articles on this site that show you how to write simple C++/CLI dlls to call native code.
Life, family, faith: Give me a visit.
From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of."
Judah Himango
|
|
|
|
|
How may I stop a running method if it takes longer than 10 seconds. I want a procedure called hello() to be called 200 times in a loop & I want the method to be aborted & the loop to be broken if the hello() methods, fails to respond in 10 seconds. How may I do this?
|
|
|
|
|
semiramisContraA,
You've already asked that question Here[^]
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
I know but unfortunately I didn't get any useful answers!
|
|
|
|
|
Do you want to break the loop if the total time is longer than 2000 seconds, or do you want each Hello call to time out after 10 seconds? Can your code handle some Hello calls running concurrently?
Semicolons: The number one seller of ostomy bags world wide. - dan neely
|
|
|
|
|
If you posted it somewhere already and you didn't get any un-useful answers, and you repost on the same site that exact same question then you will get the same un-useful answers and aggrivated codeprojectians as well.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
I Think you are wrong, the second time I posted the message, I got the answer, I was looking for.
In this site as the posting load is very high, your post gets buried under other ones very soon, so many people who may know the answer do not get the chance to read it, by reposting a request you double the chance.
|
|
|
|
|
Start the method in it's own thread, then if it doesn't respond for a while you could end it.
I'm not sure why you'd want to do this though, what would cause the method not to respond?
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Thank you for your response, I've tried multi threading, but as I do not want to use of static functions, it doesn't work.
I'm writing a code which is about to measure the vulnerability of a web service facing dos(denial of service) attacks. So I'm calling a method of a specific service 500 times to see if it is able to handle the requests. So you see that I should be able to abort the calls if the service, fails to answer.
|
|
|
|
|
have a look at the backgroundworker class.
|
|
|
|
|
I'm getting an InvalidOperationException with the following message:
"Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function."
Essentially, the context is this:
Initially, I do something like this:
BindingSource bds = new BindingSource(dataSet1, dataTableString1);
dataGridView1.DataSource = bds;
But, say I perform an operation on the datagrid which makes me want to reload the entire datagrid. What I do is something like this:
dataGridView1.DataSource = null;
dataGridView1.DataBindings.Clear();
dataSet1.Clear();
sqlDataAdapter1.Fill(dataSet1);
BindingSource bds = new BindingSource(dataSet1, dataTableString1);
dataGridView1.DataSource = bds;
The exception is thrown on the first statement when the data source is set to null. I've looked around and it seems like various situations will cause this issue, but not enough to give me a good idea on how to fix it.
|
|
|
|
|
Cyrilix wrote: dataGridView1.DataSource = bds;
That should be sufficient to replace the datasource.
|
|
|
|
|
I will give that a try.
Thanks.
|
|
|
|
|
You maybe have to 'reset' your bindings on the bindingsource if I remember correctly. But you should never have to clear it AFAIK
|
|
|
|
|
I also encounter the same problem, anyone here have solution for this problem?
|
|
|
|
|
Whoa, this thread is old. Well, I ended up changing a lot of code during all of this, and never really got down to the bottom of the problem, so I scrapped the idea. Essentially, I was trying to change a DataGrid into a DataGridView, although there was probably other existing code and assumptions I wasn't aware of, that caused this problem.
Sorry I couldn't be of more use.
|
|
|
|
|
Hello,
I am writing a simple C# program that will play an AVI file in a Form. I am able to currently do this by specifying the path for the file, and telling my program to open it from there. However, I would like to be able to somehow include this video as a part of the compiled .exe, so that, for example, I could play this video on another computer which doesn't have the video on its hard disk.
I have tried this by going to Properties, then "Add Existing File", and then browsing and finding my video file. This seemed to work fine, until I then tried to build the project, and I got the error:
The "GenerateResource" task failed unexpectedly.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.Resources.ResXFileRef.Converter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at System.ComponentModel.TypeConverter.ConvertFrom(Object value)
at System.Resources.ResXDataNode.GetValue(ITypeResolutionService typeResolver)
at System.Resources.ResXResourceReader.ParseDataNode(XmlTextReader reader, Boolean isMetaData)
at System.Resources.ResXResourceReader.ParseXml(XmlTextReader reader)
at System.Resources.ResXResourceReader.EnsureResData()
at System.Resources.ResXResourceReader.GetEnumerator()
at Microsoft.Build.Tasks.ProcessResourceFiles.ReadResources(IResourceReader reader, String fileName)
at Microsoft.Build.Tasks.ProcessResourceFiles.ReadResources(String filename, Boolean shouldUseSourcePath)
at Microsoft.Build.Tasks.ProcessResourceFiles.ProcessFile(String inFile, String outFile)
at Microsoft.Build.Tasks.ProcessResourceFiles.Run(TaskLoggingHelper log, ITaskItem[] assemblyFilesList, ArrayList inputs, ArrayList outputs, Boolean sourcePath, String language, String namespacename, String resourcesNamespace, String filename, String classname, Boolean publicClass)
at Microsoft.Build.Tasks.GenerateResource.Execute()
at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult) WindowsFormsApplication3
I don't know what this means, but it seems to suggest my video file is too big to be a resource or something. The video file is an uncompressed AVI file, but it is only 250 MB, so surely this can be a part of the executable?
If not, then is there a way that I can keep the video file and the .exe file separate, but allow the .exe file to use the video file? (without specifying the path name.)
Another quick question - I have tried adding a bitmap as a resource, and this has worked fine, but how do I then use this file? For example, if I wanted to display this bitmap as the image in a picture box, how do I reference the bitmap in the resources?
Thank you for any help on this!!
Ed.
|
|
|
|
|