Hello!
Please take a look at the following code:
Public Sub Method(Of TEntity As EntityObject)(ByVal entity As TEntity)
If TypeOf entity Is Contact Then
Dim contact As Contact = entity 'Compile error'
Dim contact = DirectCast(entity, Contact) 'Compile error'
Dim contact = CType(entity, Contact) 'Compile er...
I have saved an ArrayList to the session object. I am trying to retrieve it using
sriList = session.getAttribute("scannedMatches");
I am getting the compile time error "Cannot convert from Object to ArrayList". How can I get my ArrayList back from the session object.
...
There is something that I cannot understand in C#. You can cast an out-of-range int into an enum and the compiler does not flinch. Imagine this enum:
enum Colour
{
Red = 1,
Green = 2,
Blue = 3
}
Now, if you write:
Colour eco;
eco = (Colour)17;
The compiler thinks that’s fine. And the runtime, too. Uh?
Why did the C# te...
I wrote a class that has a map of <String, Object>. I need it to hold arbitrary objects, but at the same time sometimes I need to cast some of those objects, so I'll do something like
HashMap<String, Object> map = new HashMap<String, Object>();
Object foo =...
I want to do something like this:
List<Child> childList = new List<Child>();
...
List<Parent> parentList = childList;
However, because parentList is a List of Child's ancestor, rather than a direct ancestor, I am unable to do this. Is there workaround (other than adding each element individually)?
...
I need the Cache class that keep the <TKey key, TValue value> pairs. And it is desirable that TKey can be any class that supports Serializable interface and TValue can be any class that supports Serializable and my own ICacheable interfaces.
There is another CacheItem class that keeps <TKey key, TValue value> pair.
I want the Cache cla...
The ReportInfo is a structure. The structure works fine on one web page but I am trying to use it on another web-page. Here is where I saved the ReportInfo structure to the Session Variable
Session["ReportInfo"] = reportInfo;
On the other web-page, I re-created the Structure and then assign the session variable to it, like this...
r...
Is there a way I can explicitly cast one Java object to another Java class from JRuby?
Sometimes I want to be able to invoke SomeJavaClass#aMethod(MySuperClass) rather than SomeJavaClass#aMethod(MyClass) from JRuby.
From Java, I'd do this:
someJavaObject.aMethod( (MySuperClass) myObj );
but I didn't see a #cast ruby method or an...
Hi All,
I want to know why below downcast fails @ run time:
case 1:
Object y = 10.23;
Console.WriteLine(y.GetType()); //System.Double
int z = (int)y;// fails @ runtime
Console.ReadKey();
case 2:
enter code here Double y = 10.23;
Console.Wr...
I have a generic class and I want to enforce that instances of the type parameter are always "cast-able" / convertible from String. Is it possible to do this without for example using an interface?
Possible implementation:
public class MyClass<T> where T : IConvertibleFrom<string>, new()
{
public T DoSomethingWith(string s)
{
...
I'm still trying to map my deep and old knowledge from C/C++ to my somewhat more shallow .Net knowledge. Today the time has come to "as" (and implicitly "is" and cast) in C#.
My mental model of "as" is that it's a QueryInterface or dynamic_cast (a dynamic_cast with pointer argument, not reference, that is) for C#. My question is two-fol...
I have two vector classes:
typedef struct D3DXVECTOR3 {
FLOAT x;
FLOAT y;
FLOAT z;
} D3DXVECTOR3, *LPD3DXVECTOR3;
and
class MyVector3{
FLOAT x;
FLOAT y;
FLOAT z;
};
and a function:
void function(D3DXVECTOR3* Vector);
How is it possible (if it's possible) to achieve something like this:
MyVector3 vTest;
f...
I have two functions:
void free_this(THIS *this)
{
THIS *this_tmp;
while (this_tmp = this)
{
if (this->str)
free(this->str);
this = this_tmp->next;
free(this_tmp);
}
}
void free_that(THAT *that)
{
THAT *that_tmp;
while (that_tmp = that)
{
if (that->id)
...
Judging by the title of this question, what I want to do may not be possible so I will describe what I'm doing and you can feel free to let me know what I'm doing wrong and what would be a better way to accomplish my goal.
I have an XML file that describes 1) a custom object that is derived of a base type, and 2) the internal field name...
Suppose I have a custom control like:
MyControl : Control
if I have code like this:
List<Control> list = new ...
list.Add (myControl);
RolloutAnimation anim = list[0];
I know I can do it at compile time but I wanna do it at runtime and access MyControl specific functionality.
...
I need to convert an integral type which contains an address to the actual pointer type. I could use reinterpret_cast as follows:
MyClass *mc1 = reinterpret_cast<MyClass*>(the_integer);
However, this does not perform any run-time checks to see if the address in question actually holds a MyClass object. I want to know if there is any b...
I would like to change a column in SQL Server from type int, to type text, while maintaining the column name. The table with this column has lots of data, and I do not want to lose it. SQL Server doesn't seem to support implicit or explicit casts from int to text, otherwise this would be pretty simple. So, how would you do it using on...
Is there a way to cast a System.Object to byte*?
...
I have a DataSource in my control which is always a List<T> where T has to inherit from IEntity.
public class MyClass<T> where T : IEntity
{
public List<T> DataSource
{
get;
set;
}
}
Now, obviously you can't cast a List<T> to a List<IEntity> doing the following:
List<IEntity> wontWork = (List<IEntity>)this...
I've defined the following generic class
public class ManagedClass<T> where T : ManagedClass<T>
{
static ManagedClass()
{
Manager = new ObjectManager<T>();
}
public static ObjectManager<T> Manager { get; protected set; }
public ManagedClass()
{
Manager.Add( (T)this );
}
}
The idea is that I...