A couple of semantic questions...
Okay... I have been working with C# for a while now and I am curious about a
First, when I code something like:
public void TestFunction(ushort n)
for (ushort i = n - 1; i >= 10; i--)
//do something here;
I get a compiler error that tells me that it can not implicityly convert
type 'int' to 'ushort' on the i = n -1. What is up with that? Both i and n
are ushorts... does C# automatically make make n-1 behave as if it were i =
(int)(n-1)? Is there a nice way around it other than explictly casting n-1
as a ushort as in i = (ushort)(n-1)?
Second, Why is sizeof an unsafe operation? And further if sizeof is going
to have to take a type instead of a variable then why can't I do something
like sizeof(variable.GetType)? Is there some nice way to get the size of a
Finally, why can't a System.Array be used as the basis for an Indexer? I
have a case where I don't want to declare the type on the Array until run
time but I would like to use that Array as the basis for an Indexer. See
the example below.
public class SecBlock
private ushort size;
private Array ptr;
public SecBlock(ushort size, Type t)
this.size = size;
ptr = Array.CreateInstance(t, size);
public object this[ushort column]
ptr[column] = value;
This give a compiler error stating that Array can't be used as a basis for
an Indexer. Now, an ArrayList would be better because I need the array to
be able to dynamically grow, but then the question becomes how do I assign
the type to an ArrayList at runtime.
Any help on any of these issues would be most appreciated.
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL