|
|
hi leppie,
thank you fast reply.
how would you set NULL state for those 2 references if you know only one of them?
luke
|
|
|
|
|
You can't. There is no backward reference from the object to it's references.
This sounds like the all too common situation where someone tries to fix bad programming with some magic command. You just have to keep track of your references.
---
b { font-weight: normal; }
|
|
|
|
|
thanks. ok, i'll just keep the track
|
|
|
|
|
This sounds like the all too common situation where someone tries to fix bad programming with some magic command. You just have to keep track of your references.
I was thinking that this sounds like the all too common situation where someone tries to fix bad programming with even worse programming.
Why in the heck would you want to null out references about which you know nothing? Just for the pleasure of seeing those lovely unhandled NullReferenceExceptions ? (Okay, I suppose that would provide a first step in tracking down those references that you couldn't find, but the OP didn't say that was the goal (if it was, mock objects would probably be a better solution anyhow)).
Matt Gerrans
|
|
|
|
|
I have noticed that I need not put any DLLImport statements in Windows application if I am using some DLLs. I just need to add those DLLs in the reference and then use it.
My question is when is it necessary to have a DLLImport statement in my C# code?
Thanks and Regards,
Amit
|
|
|
|
|
The DllImport are required when you want to call into pre-.NET DLL, i.e. C dll.
If it's a .NET dll (i.e. an assembly) no problem, if it's a C DLL, you need to do interop.
Interop is a vast topic but well documented in the SDK's documentation, I suggest you to refer to it.
Basically C# need to know about the function to use it, right?
C DLL define no metadata that could be used by other .NET dlls to knwo about its content (they just define C header usable by a C compiler), therefore you have to do these declaration yourself.
That's the purpose of DllImpoert.
You've got most of win32 API Interop declaration there:
http://pinvoke.net/[^]
|
|
|
|
|
Thanks for the answer. It, indeed, answers most of my initial questions. Now, I am trying to write a wrapper for LAPACK [http://www.netlib.org/clapack/faq.html], which is available in C and FORTRAN in C#. It is a highly optimized linear algebra subroutines. Do you have any idea about a place where I can go to learn the secret of the "writing wrappers in C#" business.
Thanks and Regards,
Amit
-- modified at 20:24 Friday 26th August, 2005
|
|
|
|
|
You should really learn to use the documentation coming with the SDK.
In the "index" side panel there is a box named "look for", just type: "interop", "COM interop" or "data marshaling" in it and you will find a wealth of information.
Alternatively, if you've got issue with the SDK documentation (strangely many .NET developer seems to ignore about its existence) you could go on MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconinteroperatingwithunmanagedcode.asp[^]
Anyway about array marshaling (let's say float[]) the documentation doesn't straightforwardly explained you wether or not the whole array is copied or not to a temporary buffer every crossing the managed/unmanaged boudary (I think some attributes control that behavior).
But always have the solution to use unsafe code & float* in C# or, as I prefer to write my wrappers now, use ManagedC++ (v2.0, meach cleaner, leaner and less ambiguous).
|
|
|
|
|
I have come across this wrapper word many times. Many people have written wrappers for C# for subrountines which are not written in C#. My question is what this wrapper is and how it can be used as to include other sub-routines in a C# application?.
Regards and Thanks,
Amit
|
|
|
|
|
Basically in C# you can call directly into C function that's "easy" thanks to interop!
But you still have to declare the C function in C#, with correct data structure, sometimes it's not so trivial toredefine in .NET the C data structure. You might also have many function to re-declare, quite tedious, particularly if there is, let's say, hundreds of them!. And you might as well simplify the C# API compare to the C API.
It's what a wrapper is for.
|
|
|
|
|
How do I pass a two doubles as a PointF args?
I converted them from a TextBox using Convert.ToDouble...
If I can't do it, any way around it?
thanks in advance....
|
|
|
|
|
is it a joke? what are you trying to do?
just in case you ask for the obvious and missed it, let me state it:
PointF ToPointF(double x, double y)
{
return new PointF((float) x, (float) y);
}
if it is what you were looking for and didn't find it I suggest you read: "Learning C#" by Someone...
|
|
|
|
|
Thanks. I didn't know only experienced progarmmers could ask questions.
I hope that maybe someday I can be a self proclaimed genius just like you.....
|
|
|
|
|
Aheum....
Let's say it always comes as a surprise (a shock?) to see how inexperienced an inquiring developer could be.
But well, I guess we all have to start somewhere, someday, ...
Myself, I remember when I was young... mouahahaha
|
|
|
|
|
You got me. But at least I know how to do it now....Sometimes I go right to posting a message instead of spending some time with MSDN help.....
|
|
|
|
|
SkunkedWorks wrote:
Sometimes I go right to posting a message instead of spending some time with MSDN help...
Believe me, I've been working with programming for more than 20 years, now: the time you spend with MSDN teaches you a lot more than you notice. On online forums, people will teach you exactly what you asked for, and often in MSDN, you'll find a lot of other interesting things while looking for an answer.
I see dead pixels
Yes, even I am blogging now!
|
|
|
|
|
|
<br />
int counter = 0; <br />
ArrayList Numbers = new ArrayList(); <br />
Regex regex = new Regex(@"(.+);(.+);(.+)");
Match matchit = regex.Match("Gerald; 0650123456; Sabine; Spech; 06761233333"); <br />
<br />
for (int i = 0; i < matchit.Groups.Count; i++) <br />
{ <br />
Numbers.Add(matchit.Groups[i].Value); <br />
MessageBox.Show(Numbers[i].ToString().Trim()); <br />
}<br />
hi the regex here don't work...i want to make it, that it works for:
"Gerald; 0650123456; Sabine; Spech; 06761233333"
result:
Numbers[0] = Gerald;
Numbers[1] = 0650123456;
Numbers[2] = Sabine;
Numbers[3] = Spech;
Numbers[4] = 06761233333;
and for:
"Gerald; 0650123456; Mike"
result:
Numbers[0] = Gerald;
Numbers[1] = 0650123456;
Numbers[2] = Mike;
the regex have to be independent from the length of the input string....
cu
|
|
|
|
|
Try to use the following regex expression:
Regex regex = new Regex(@"[\w\d ]+;[\w\d ]+;[\w\d ]+");
the expression stands for:
at least one word, digit or space followed by semicolon
and
at least one word, digit or space followed by semicolon
and
at least one word, digit or space.
Let me know if it's ok
Uri
|
|
|
|
|
|
Hi,
Maybe I didn't understand the requirements of your regex, because the regex I have provided returns a valid value for exectly 3 words or digit sets seperated by a comma.
Could you provide me with more info about the results you are expecting to have ?
|
|
|
|
|
the regex should not only works for 3 words! for 9 words too...
looks like that:
"Gerald; 067612345; Sabine"
or
"Gerald; 067612345; Sabine; Mark; 065012233"
than i want to have the names or numbers in an array:
array[0] = Gerald
array[1] = 067612345
array[2] = Sabine
array[3] = Mark
array[4] = 065012233
cu
|
|
|
|
|
Hi,
* use the following expr. @"(?>\w|\d)+;?)"
* use the Matches method and not the Match method as follows:
ArrayList Numbers = new ArrayList(); <br />
Regex regex = new Regex(@"(?>\w|\d)+;?");
MatchCollection collection = regex.Matches("Gerald; 0650123456; Sabine; Spech; 06761233333");<br />
foreach(Match m in collection)<br />
{<br />
Console.WriteLine("**" + m.Value);<br />
}
-- modified at 12:12 Saturday 27th August, 2005
|
|
|
|
|
hi, looks good!
but the output is:
Gerald;
0650123456;
Sabine;
Spech;
06761233333
i dont need the ;
i can use substr but can i solve that with regex only?
cu
|
|
|
|