|
Correct, the term to remember here is "overload".
|
|
|
|
|
You don't need to override ToString if your passing arguments.
Every object has a default ToString() with no parameters, which will return the objects name. If you need your own paramaterless ToString then you use override to override the default method with the same signature.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
I'm not following you.
My struct has two fields. The default ToString() simply returns the name of the struct.
I want my ToString to either return the format I provided {122345.67879} or, say, the same fields in hex {FFFFF.00000}.
(yes I realize that's not proper hex)
So how do I write my ToString override to accept an argument (like "X")?
|
|
|
|
|
Voting 1 because you don't understand isn't going to get you very far on these forums!
I'm in a good mood today however so how about something like this?
public override string ToString()
{
return ToString(string.Empty);
}
public string ToString(string format)
{
return "{" + highID.ToString(format) + "." + lowID.ToString(format) + "}";
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Thanks - apparently the fix is not including the "override" declaration in the second ToString() method. This was preventing it from compiling.
|
|
|
|
|
You just need to crate one more method in you structure with ToString which contains single argument. like
<pre>
public struct IITObjectPersistentID {
public int highID;
public int lowID;
public IITObjectPersistentID(int HighID, int LowID)
{
highID = HighID;
lowID = LowID;
}
public override string ToString()
{
return "{" + highID.ToString() + "." + lowID.ToString() + "}";
}
internal string ToString(string str)
{
//Do ur code here
}
}</pre>
|
|
|
|
|
Hi,
there are no optional parameters in C#; each combination of parameters results in another method.
ToString() and ToString(string) are two different methods that share their name, but not their signature
(=list of parameter types).
Object class has a ToString() but not a ToString(string).
So when you class derives from Object, it needs an override to provide its own ToString()
and it is not allowed an override keyword on ToString(string).
|
|
|
|
|
Hi,
I load sql data in datagridview, combobox, textbox but i can´t do it to statusstrip object.
At least in normal way. I pass it to other object and then to it.
Any sugestions?
thanks
|
|
|
|
|
Can you explain in a bit more detail what you are trying to do. Putting data into a StatusStrip object is no different from other controls, the difference is that you can't do it easily through the designer (which is what I suspect you're trying to do) but you can through code.
|
|
|
|
|
hi,
I have a application with 1 form (main_form) and 6 usercontrols(login_page, menu_page, item1_page, item2_page, item3_page, item4_page).
The form has inside all usercontrols!!!
When i want to enter menu_page i edit visible = true, and visible = false to other usercontrols
i use delegates to trigger events within any usercontrol or form
it works
someone does it other way?
|
|
|
|
|
Sounds kinda like a home-grown tab control.
At least you're using usercontrols.
You'd have to describe more about how the user navigates.
Depending on what you're doing, I would probably pop up (modal) dialogs.
Typically, when the form loads, I would pop up the login_page.
Once logged in, the user sees the menu_page.
When the user selects a menu item, I pop up the appropriate item_page.
But, like cats, there are many ways to skin it.
|
|
|
|
|
hey im trying to make a program that uses some http features and analyze the response data ,
i have encounter a problem when i get responses which are encoded in this method:
Transfer-Encoding: chunked
Content-Encoding: gzip
does anyone have an idea how can i decode the returned data ?
so it will be readable.
thank you.
Net
modified on Friday, July 25, 2008 5:59 PM
|
|
|
|
|
I write a windows service. It's log on as Local System account. I want to log on as user account for this service. For example administrator account or any other user account on windows. Ok, I can change Local System account to user account using with this steps;
My Computer --> Manage --> Services and Applications --> Services --> "MyService"
Click "LogOn" tab
Select "This account"
This account: type your account (For example .\Administrator)
Password: type your password
How can I write this operation code in C# ?
Best Regards...
|
|
|
|
|
|
I have a loop (below) that has 64 iterations. Every 8 iterations i want to change an int. At the moment, i do the below, but its not a "nice" way to do to.
for (int i = 0; i < 64; i++)
{
if (i == 7 || i == 15 || i == 23 || i == 31 || i == 39 || i == 47 || i == 55)
{
}
}
So, does anyone know how I'd do a calculation to have the same effect as the above?
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Hi,
Use modulus operator (%) and check that the remainder is 0
For example: 7%7 and 14%7 returns 0 while 8%7 and 15%7 returns 1 and so on.
for (int i = 0; i < 64; i++) {
if (i % 7 == 0) {
}
}
[addition]
Of course if you don't actually need the values between you can modify your loop incrementation:
for (int i = -1; i < 64; i=i+8){
if (i == 7 || i == 15 || i == 23 || i == 31 || i == 39 || i == 47 || i == 55) {
}
}
[addition ends]
Hope this helps,
Mika
modified on Friday, July 25, 2008 5:33 PM
|
|
|
|
|
Cheers.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Hi Gareth,
for powers of 2, don't use modulo, use bitwise AND instead. As in
if ((counter & 7)==0) doEveryEightTime();
|
|
|
|
|
Gareth H wrote:
for (int i = 0; i < 64; i++)
{
if (i == 7 || i == 15 || i == 23 || i == 31 || i == 39 || i == 47 || i == 55)
{
}
}
So, does anyone know how I'd do a calculation to have the same effect as the above?
int counter = 0;
for (int i = 0; i < 64; i++, counter++)
{
if (counter == 7)
{
counter = -1;
}
}
-OR- (additional maths needed but without an extra variable)
for (int i = 0; i < 64; i++)
{
if (i % 8 == 7)
{
}
}
Hope it helps .
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Just use the modulus operator (%), like so...
private bool IsDivisibleBy(int divisor, int value)
{
return (value % divisor == 0);
}
if (IsDivisibleBy(8, 32))
{
}
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
I would like to share with the .NET community, the NetAsm opensource project available on codeplex.
NetAsm provides a hook to the .NET JIT compiler and enables to inject your own native code in replacement of the default CLR JIT compilation. With this library, it is possible, at runtime, to inject x86 assembler code in CLR methods with the speed of a pure CLR method call and without the cost of Interop/PInvoke calls. With this library, it is possible for example to inject highly optimized code (using SSE, MMX) inside a method, in replacement of the default generated native code by the JIT compiler.
The current features of NetAsm are:
- Runs on x86 32bit Microsoft .NET platform with 2.0+ CLR runtime (x64 may be supported in the future
- Provides three different native code injection techniques: Static, DLL, and Dynamic.
- Static code injection: The native code is stored in an attribute of the method.
- Dll code injection : this method is similar to the DllImport mechanism but CLR methods are directly bind to the DLL function, without going through the interop layers.
- Dynamic code injection: you can generate native code dynamically with a callback interface that is called by the JIT when compilation of a method is occurring. It means that you can compile a method “on the fly”. You have also access to the IL code of the method being compiled.
- Supports for debugging static and dynamic code injection.
- Supports for different calling conventions: StdCall, FastCall, ThisCall, Cdecl. Default calling convention is CLRCall
- NetAsm can be used inside any .NET language (you can run assembler code inside VB!)
- Very small library <100Ko.
For additional information and documentation, please visit the NetAsm codeplex site.
Alexandre
|
|
|
|
|
I'm not sure where you should post this - maybe an article giving a demonstration of your project in use so people can see its benifits in action? - but certainly not here in this forum!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
>>but certainly not here in this forum!
Why not?
it's not a commercial product, it is related to the topic of the forum and it could be useful for the readers in here.
I don't see why it shouldnt be here..
|
|
|
|
|
Hi,
I have to create a parser that can parse a HL7 Message and load the data result into aSQL Server.
Does any one have any idea about this ?
|
|
|
|
|
I know nothing about this personally but a quick search found this blog[^] - the author seems to be pretty knowledgeable and there's alot of info on his site.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|