|
using System.Linq, thats the one.
Thanks Eslam!
|
|
|
|
|
You're welcome.
Eslam Afifi
|
|
|
|
|
Therein lies a great deal of what I don't like about extension methods.
|
|
|
|
|
and what might that be?
only two letters away from being an asset
|
|
|
|
|
People not knowing where they are and not even knowing that they are extension methods.
At least as regular static methods it's clearer that the method is not part of the type.
Exension methods are a form of obfuscation.
But that's just me.
|
|
|
|
|
PIEBALDconsult wrote: even knowing that they are extension methods.
VS shows extension methods with a different icon in intellisense, right?
|
|
|
|
|
Not everyone uses VS. Snippets of code posted here don't have intellisense either. Nor do printouts
Don't rely on the behaviour of any one tool.
modified on Friday, January 23, 2009 1:26 AM
|
|
|
|
|
The semantics of an extension method are correct, and they increase code readability. They are certainly preferable than buggering up the type heirarchy with things like "MyListWithExtraStuff : List". They also allow you to extend any type which supports a particular interface, which is a powerful feature - almost like half-baked multiple inheritance.
myFoo.Baz(bar);
Is Baz an extension method? Does it matter? As long as it "bazzes" as documented, then it is no different from a normal method.
|
|
|
|
|
Mark Churchill wrote: The semantics of an extension method are correct
Because they added those semantics.
Mark Churchill wrote: they increase code readability
My opinion is that they do just the opposite.
Mark Churchill wrote: any type which supports a particular interface
Just like regular static methods.
Mark Churchill wrote: almost like half-baked multiple inheritance
You may be onto something there. Or maybe just on something.
Mark Churchill wrote: Does it matter?
Of course it makes a difference. Not to the original developer, not to the compiler, but when communicated between developers, particularly inexperienced ones.
I'm well aware that I take the minority view on this and many other things, but I'm not the only one. Others [weasel words] have the same and other concerns. I do write an occasional extension method (see my recent "Untabify and Tabify"[^] article), but I try to make it clear that extension methods are in use.
|
|
|
|
|
I'm trying to use a bluetooth device as though it were a socket. I am aware that this can be done using WINSOCK and P/Invoke, but to be honest I really don't want to put myself through that just yet . With WMI I can get the MAC address that the BT Dongle is using, but can I use the MAC Address to create a socket with .NET?
Scott P
"Simplicity carried to the extreme becomes elegance."
-Jon Franklin
|
|
|
|
|
Nope. The MAC address sits in the DataLink layer of the network stack, whereas sockets exist in the Network layer. You can't combine the two with any meaning. You'd have to resolve the MAC address to a Network layer address in order to create a socket.
|
|
|
|
|
Microsoft has encapsulated bluetooth communciation in their socket layer as an extension to Winsock.
There are a few APIs also provided that have the name BluetoothXXX.
Winsock would be your best bet on this.
Or you would have to go very low level as Dave mentioned.
«_Superman_»
|
|
|
|
|
Hi all!
(Sorry for my bad English...)
I need to read a value in a memory address. I don't need to change that value, just need to read it. Reading from a pointer would be better, but not that important if it would be much more hard than just reading a value in a memory address. I tried googling to find something, but can only find tutorials about making game trainers, but I don't need all that stuff, and actually I don't understand them.
Can anyone help me?
Edit:
I mean... I need to read the the value of a given memory address (or the pointer to that address) of a given running application. But don't know how to actually do that! I found this on the net "To pull this off you'll need to PInvoke OpenProcess and ReadProcessMemory." but I can't find a guide nor an example code about how using that to read memory. That's what I'm looking for...
modified on Thursday, January 22, 2009 6:58 PM
|
|
|
|
|
AFAIK C# isn't your best choice for access memory outside of the scope of the application. I'm pretty sure C# cannot use pointers as C++ can.
What is the goal of your project, surely there is a workaround.
|
|
|
|
|
EliottA wrote: I'm pretty sure C# cannot use pointers as C++ can.
It can - all you need to do is wrap it in an unsafe region.
|
|
|
|
|
Ahh I wasn't sure, sorry for the misinformation
|
|
|
|
|
Even if you wrap something in an unsafe scope, or mark a method as unsafe, .NET will still perform bounds checks on pointers. If you need to read an arbitrary location in memory, you would likely need to use an unchecked {} scope as well.
|
|
|
|
|
.NET never performs bound checks on pointers. That's why they're unsafe .
unchecked {} only affects integer overflow checking, it is unrelated to bounds checking.
|
|
|
|
|
Thats not entirely true. If you create a pointer to an object, and try to advance the pointer beyond the range of memory that object consumes on the heap, C# throws an exception. Your free to move the pointer to any location that on the heap that is part of the object you originally created the pointer from, but nothing ouside of it. Only when you wrap your ponter logic in an unchecked {} block are you able to access memory beyond the bounds of whatever it was you originally set the pointer to.
|
|
|
|
|
Do you have any references for that?
In my understanding, "int* IncrementPointer(int *p) { return p++; }" is a simple increment of the pointer, no runtime checks. It doesn't matter whether p points to unmanaged memory or a pinned object on the GC heap.
.NET doesn't even try to remember the 'valid range' - it's just a simple pointer!
Looking for 'unchecked' in the C# specification, it only talks about integer overflows. No mention of pointers there.
However, when you dereference an invalid pointer, you might get a nice managed exception. But that's just because .NET converts Win32 access violations to exceptions (to NullReferenceException if the pointer was near null, AccessViolationException otherweise). It is still possible to read invalid data/crash the process/whatever - they're unsafe pointers!
|
|
|
|
|
I ran into the problem a while back on a project that was using pointers to manipulate a Bitmap object. I had a bug in my math tha was causing me to read past the end of the bitmap, and I was getting an AccessViolationException. I'll see if I can dig the code up. Interestingly enough, I just tried to proove the theory by writing a simple loop that passed over an array with a pointer, and when reading past the end, I recieved neither a NullReferenceException nor an AccessViolationException. Given that, perhapse the exception was something specific to the Bitmap class in .NET...
|
|
|
|
|
To use pointers in C# you must use unsafe code either through the compiler option /unsafe or through an unsafe block. After that the code is the same in C++ and C#. My article on Grayscale conversion uses pointers.
http://www.codeproject.com/KB/graphics/quickgrayscale.aspx[^]
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: either through the compiler option /unsafe or through an unsafe block
Don't you need both?
|
|
|
|
|
Yes.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Anybody help me
i am new c# developing. i want dynamic drag window component for example the label or button will move after execute the project .
And one more thing on that time want call back method, if the label drag on the another label of same form
Thankyou
|
|
|
|