|
Vasudevan Deepak Kumar wrote: He is asking about in a web application on a web browser. This wouldn't work in that case.
Ah. Didn't see that
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
caradri wrote: I'am working in a web page and I want to open a save as dialog box when the client click on the download botton, and, obviously, download a file to the path that he desired.
Check out this http://support.microsoft.com/kb/260519[^]
caradri wrote: I need to capture the path where he want to save the file? I do this from the save as dialog box that I don't now make it?
You can not do this and you need not. The file saving would be handled by the web browser itself.
caradri wrote: cant use system.windows.form in the web. that's OK
That's correct.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.
|
|
|
|
|
Hi,
how can I call static method on a Type variable, when following is known:
- there is a Class 'A', which implements a static method - public static int GetValue().
- there may by several subclasses 'B, C ,D ,E' where all of them derive from A , so they all derive GetValue() method.
- some of subclasses may want to override GetValue() ( declare public new static int GetValue()) and return different value than parent class ('A') returns.
now, I have a variable of type Type :
Type myType;
and I know that myType contains one of subclasses of A class.
how can I call static GetValue() on myType (withount instantiating it!!!)
I hope it's not confusing )
thanx
zilo
|
|
|
|
|
MethodInfo inf = myType.GetMethod("GetValue");
inf.Invoke(null, new object[] parameters );
if it's static it will ignore the first parameter (null);
|
|
|
|
|
thanx
that's what I used, but I (am) was curious if there is a "nicer" way how to do that.
zilo
|
|
|
|
|
Well, guess you could use generics too, if reflection isn't nice enough for you (although that's not necessarily better way to do)
|
|
|
|
|
ok, it works, but the thing is, that when GetValue is not overridden in subclass, reflection doesn't return parent method but null. And when I think about it, it's probably better that way. I can call parent method anyway...
zilo
|
|
|
|
|
Guess it's better with generics then, cuz you don't have to worry about wether it overrides or just inherits.
|
|
|
|
|
Can you be more specific how to do that with generics?
Anyway , I can't use generics, cause that method is a part of a control (Form) and there is a bug regarding Designer and generics. It would not display child classes (Forms) in Designer at all. It's bug by design...
zilo
|
|
|
|
|
Involved not changing return types. Another option is to create a generic method.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
Hi All,
I'm attempting to test if a high bit is set on a octet. C# is stating:
An unhandled exception of type 'System.OverflowException' occurred in mscorlib.dll
Additional information: Value was either too large or too small for an unsigned byte. Any ideas how to work with bit values in C# without losing semantics (readability)? At this point, I'd also take something that works as expected (or works as I expect).
Jeff
ArrayList Octets = new ArrayList();
...
Int32 i=0;
while( i < Octets.Count )
{
Byte b = Byte.Parse(Octets[i].ToString());
b &= unchecked(Convert.ToByte(~0x80));
if( 0x00 == b ) { break; }
....
i++;
}
|
|
|
|
|
Hi Jeffrey,
I am not sure what type it is you originally put into the ArrayList, I will assume the
item type is byte.
Here are some ideas:
- I see no point in using Parse(...ToString()), that is turning a number to a string to
get a number again. why not treat the ArrayList item directly? Of course ArrayList only
returns type object, so you would have to cast to the original type, as in
(byte)Octets[i]
- in general, bit manipulations are easiest on unsigned numbers, so byte is OK
- your problem statement is not doing what you intend: ANDing with the complement of 0x80
is ANDing with 0x7F, that is stripping off the highest bit; a subsequent zero-test will
return true iff the original value was either 0x00 or 0x80.
- testing any bit can be achieved by ANDing and comparing to zero; testing the highest bit
would require something like: if ((b & bMSB)!=0) MSB_is_set; else MSB_is_clear;
where bMSB could be a byte variable initialized to 0x80u (u suffix for unsigned).
- you can use foreach instead of for to iterate over a collection. It does not need
an index variable, you can and must specify both the type and the name of the object itself
you are getting from the collection; as a bonus you don't need to cast the ArrayList
element anymore.
So this is what I would suggest:
byte bMSB=0x80u;
ArrayList Octets = new ArrayList();
...
foreach (byte b in Octets) {
if((b & bMSB)!=0) break;
....
}
Furthermore, you could use a generic collection (available since .NET 2.0), in this case
a List<byte> instead of an ArrayList, although the difference would be minor here.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi Luc,
Thank you very much for the comprehensive response. Here's the next issue (I did not like the ToString() calls either). Changing:
Byte.Parse(Octets[0].ToString()) to
(Byte)Octets[0] reults in Compiler Error:Error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
More awkwardness: changing from Parse() and ToString() to
(Int32)Octets[0] / 40 results in Runtime Error:An unhandled exception of type 'System.InvalidCastException' occurred in OIDFetch.exe
Additional information: Specified cast is not valid.
This is frustrating. I can understand abstracting away bit operations due to code portability. But when did operations on numbers stop being number-centric?
The situation reminds me of Java. Trying to read a file results in so many casts to so many readers, you lose the readability (semantics) of what you are trying to accomplish: FileReaders to ByteReaders to StreamReaders... I never went back to Java after college.
Jeff
|
|
|
|
|
Hi Jeff,
I agree one should avoid casts most of the time.
In what I explained, there basically was only one, and that one is due to the fact
that ArrayList stores objects, not known types, so when retrieving an ArrayList element,
you must cast it again to its real type. (The new List<byte> alternative solves that!)
I cannot figure out what is causing your compile error CS0201; I would need a larger
code snippet (yours is less than one statement, there is no semicolon, no curly bracket).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Jeff, some casting is going on here because you're using old stuff, ArrayList. Use List<byte> for the octets, and you won't need any casting.
|
|
|
|
|
Hi Judah,
Thanks. I found it in System.Collections.Generic.List<byte>. Time for another rewrite (copy and paste is my friend).
Jeff
|
|
|
|
|
Jeffrey Walton wrote: Changing:
Byte.Parse(Octets[0].ToString())
to
(Byte)Octets[0]
reults in Compiler Error:
Error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Then you obviously changed something more in that statement. If you only changed that, it would compile just fine.
Jeffrey Walton wrote: changing from Parse() and ToString() to
(Int32)Octets[0] / 40
results in Runtime Error:
An unhandled exception of type 'System.InvalidCastException' occurred in OIDFetch.exe
Additional information: Specified cast is not valid.
When you are unboxing a boxed value, you have to use the exact data type of the boxed value. Once you have unboxed it to get the byte value, you can cast it to an int if you like.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Hi Luc,
I hope it's not bad form to spawn a response for each question... I think it keeps dialogue exchange manageable.
I am not sure what type it is you originally put into the ArrayList, I will assume the item type is byte.
I used ArrayList due to a recomendation on the C# usenet group. I despise the concept of ArrayList of Objects for numbers (integers, shorts longs, etc)... I don't like the casting. I understand one may have an array of type Employee, where this makes sense.
For a 32 bit integer or 8 bit byte, this is offensive to me. What I want is a vector of bytes - no casting, perform math on the elements, etc. If C# wants to call it a collection, that is fine. But don't take away semantics of primitive operations such as v[2] = v[0] * v[1].
Luc Pattyn wrote: Furthermore, you could use a generic collection (available since .NET 2.0), in this case
a List<byte> instead of an ArrayList, although the difference would be minor here.
I'd like to try use this... Where does one find it? I did not see it in System.Collection. I imagine it is elsewhere? I am using VS 2005. I have .Net 1.1 and 2.0 Configuration Wizards, so I imagine the runtimes are installed.
Jeff
|
|
|
|
|
Hi Luc,
Found it in System.Collections.Generic.List<byte>.
Jeff
|
|
|
|
|
Hi Jeff,
"collection" (lower-case!) is the general term for an object holding a lot of objects that
can be enumerated somehow; so arrays, ArrayLists, Lists, Dictionaries, all are collections.
Array, ArrayList containing numbers, and List<some_numeric_type> v all would support
v[2] = v[0] * v[1] .
Jeffrey Walton wrote: I used ArrayList due to a recomendation on the C# usenet group.
Either that recommendation dates back from the .NET 1.x times, or it is suboptimal.
Basically List<T> is an ArrayList that only allows you to add objects of type T, and
automatically returns a type T when you access its items.
Starting with VS2005 (=.NET 2.0) a new Win app automatically gets a
"using System.Collections.Generic" and no longer a "using System.Collections".
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Jeffrey Walton wrote: b &= unchecked(Convert.ToByte(~0x80)); // Problem Here
The 0x80 literal is an int value. When you use the bitwise completent operator (~) on it, it will switch all bits in the int value, which results in the value -0x7FFFFF7F. This is clearly way too large to fit in a byte.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Hi Guffa,
Guffa wrote: The 0x80 literal is an int value.
It's a shame C# has a penchant for the Int conversion, even when I specify otherwise. For example, the following:
Byte b = 0x80;
b = ~b; results in a Compiler Error:Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?) Humorous... When I attempt to cast, it complains also. The problems would go away if the compiler would listen to the human operator and simply compliment the Byte value b .
Jeff
|
|
|
|
|
Hi All,
I believe this is the cause of my grief. Microsoft documentation states:
The ~ operator performs a bitwise complement operation on its operand, which has the effect of reversing each bit. [1] This is very misleading: it does not compliment an operand - it compliments an Int . The programmer is left to clean up the mess created by the compiler.
Jeff
[1] ~ Operator (C# Reference)[^]
|
|
|
|
|
Hi all,
What is a better design in visual studio.
To create separate datasets for each database table or
one dataset with all tables on the dataset.
Lets say the database has 30 tables.
Just want to know your opinions!
Regards
Cecil
|
|
|
|
|
cecildt wrote: What is a better design in visual studio.
Visual Studio is the IDE. You can do all this stuff in notepad if you want. It has nothing to do with Visual Studio.
cecildt wrote: To create separate datasets for each database table or
one dataset with all tables on the dataset.
Or don't use datasets at all. I don't use them much. I see no need for them. I query the database and everything gets mapped into my business objects.
|
|
|
|
|