When trying to answer this question, I discovered the following:
string s = "test";
var result1 = s.Select(c => (ushort)c); // works fine
var result2 = s.Cast<ushort>(); // throws an invalid cast exception
Why does Cast<T>() fail here? Whats the difference?
...
Introduction
I am aware that "user-defined conversions to or from a base class are not allowed". MSDN gives, as an explanation to this rule, "You do not need this operator."
I do understand that an user-defined conversion to a base class is not needed, as this obviously done implicitly. However, I do need a conversion from a base class...
Hi,
Today, I have started writing a query which is as given below:
SELECT IP1.InstId,CAST(IP2.Quote AS DECIMAL(10,2)) AS 'CurrentPrice',IP1.Quote,(IP2.Quote-IP1.Quote) AS 'Change'
FROM InstrumentPrices IP1
INNER JOIN InstrumentPrices IP2
ON IP1.InstId=IP2.InstId
INNER JOIN Instruments I
ON I.Id=IP2.InstId
INNER JOIN Games G
ON G.Id=I...
LinQ contains the method Cast which casts each entry in the list to type T. Lets say we have a list which looks like the following:
List<Object> obj = new List<Object>();
obj.Add("A");
obj.Add("B");
A working cast could be
var list = obj.Cast<string>();
What I would like to work
Type t = typeof(String);
Object list = obj.Cast(t);
...
Hi,
I have 2 tables (Document and DocumentClass) that have the following columns:
DocumentClass: DocClassID, Name, ParentID
Document: DocID, Name, DocClassID
The DocumentClass table contains parent and child records and the relationship between a parent and a child is the ParentID column. A Document record is linked with a child rec...
I have a pointer in a struct. And I passed a struct pointer to this pointer.
But I could not type cast back to this pointer to struct.
public class Test
{
//
Pointer ptr = new Memory(4);
}
public class Temp extends Structure
{
//
}
Test tst = new Test();
Temp tmp = new Temp();
tst.ptr = tmp.getPointer();
...
Temp...
Following up on InternalsVisibleTo. I have looked at c# Instantiating Internal class with private constructor, and this has helped but I'm trying to cast the returned object as the internal type and, honestly I'm not 100% that that is possible.
I'm trying the route of Reflection to fix this issue, but I'm having a tough time trying to ...
Hi! I have following problem in PHP:
print_r says its the same, gettype says same type..
but the last output works not for both cases... although they should be the same!!
this looks very strange for me...
code and output:
$docdatau = get_object_vars(json_decode($docdata));
$docdatau2 = (array)json_decode($docdata);
echo "1\n";
echo...
I am developing an SSIS 2008 package and I am trying to create a Derived Column transformation. But when I go to the Expression editor and try this expression it gives me alot of errors. I have tried various differentiations of this but all have resulted in errors. I need one of you SQL experts to point out a better expression!
IS...
public class InterfaceCasting {
private static class A{}
public static void main(String[] args) {
A a = new A();
Serializable serializable = new Serializable(){};
a = (A)serializable;
}
}
Compilation succeed but Runtime exception
Exception in thread "main" java.lang.ClassCastException: InterfaceC...
Hello overflow,
i have some low level image/texture operations where 32-bit colors are stored as UInt32 or int and i need a really fast bitwise conversion between the two.
e.g.
int color = -2451337;
//exception
UInt32 cu = (UInt32)color;
any ideas?
thanks and regards
...
Hello, I have to store a list of different boost::function objects. To provide this I'm using boost::any. I have a few functions which takes different functions signatures, pack them into any and then insert into special map with given type. Here is the code:
enum TypeEnumerator
{
e_int,
e_float,
e_double
};
typedef map< st...
I have an object in my code of the type Object:
Object o
The class of the instance is Object: o.getClass() gives Object.
Now, it should be a Map! How can I upcast this to a Map?
I tried: Map<String, Object> map = (HashMap<String,Object>)o
But this returns:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.u...
I have a method that looks like this
public static <T extends MyClass, X extends AnotherClass> List<T> (Class<T> aParameter, X anotherParameter)
Now if AnotherClass is an abstract class that does NOT Have getId defined, but every single class that extends this interface does. (Don't ask me why it is designed this why, I did not desi...
i want to sum to values which i get from a textfiel.
how can i cast a textfield value in double value ?
Regards Caglar
...
Hello All,
I have been using a driver to test one of my data structures(Binary Search Tree)
and i have come across this issue.
-It happens when i insert more than 2 objects into the bst
-What I am trying to do: I am inserting 4 objects into the tree, then i am deleting 2 objects, and then printing out my find method so that it displays ...
I have a column (varchar in mysql and a character varying in postgresql).
I need to apply sum on the column and I need a cast syntax that works for both.
The db structure is old and has both int and varchar values. I can't change that.
...
I've read a few related questions regarding this topic however none of them are making sense to me. As I understand it, in some cases you can use cast and parse interchangeably and achieve the same result.
Are there some general guidelines that can help me decide when to choose one approach over the other?
...
Has anyone come across an error like the following:
Unable to cast object of type 'CompaniesDataTable' to type 'CompaniesDataTable'.
Here is the code that is causing the error:
protected void ObjectDataSource_Companies_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
int x = ((Adala.CompaniesDataTable)(e....
I'm reading data from a custom data format that conceptually stores data in a table. Each column can have a distinct type. The types are specific to the file format and map to C# types.
I have a Column type that encapsulates the idea of a column, with generic parameter T indicating the C# type that is in the column. The Column.FormatTyp...