tagged [casting]
Object As Interface
Object As Interface I've got an object that implements an interface, I then find that object using reflection. How can I cast the object into the interface and then place it into a `List` ?
- Modified
- 29 Nov at 21:7
Cast operation precedence in C#
Cast operation precedence in C# Will the differences below matter significantly in C#? Which one do you use?
- Modified
- 29 Mar at 13:31
return single instance object as IEnumerable
return single instance object as IEnumerable I have in instance of class foo and i want to return it as IEnumerable. Can i do it without creating a new list etc.. Perhaps something like the following:
- Modified
- 3 Aug at 18:6
invalid cast exception on int to double
invalid cast exception on int to double Maybe I'm crazy, but I thought this was a valid cast: Why is LinqPad throwing a > InvalidCastException: Specified cast is not valid. ?
Haskell: Converting Int to String
Haskell: Converting Int to String I know you can convert a `String` to an number with `read`: But how do you grab the `String` representation of an `Int` value?
Why does (int)(object)10m throw "Specified cast is not valid" exception?
Why does (int)(object)10m throw "Specified cast is not valid" exception? Why this explicit cast does throw `Specified cast is not valid.` exception ? But this works:
C# and Interfaces - Explicit vs. Implicit
C# and Interfaces - Explicit vs. Implicit In C#, if a class *has all the correct methods/signatures for an Interface*, but **doesn't** explicitly implement it like: Can the class still be cast as that...
- Modified
- 2 May at 02:43
What is the difference between casting and conversion?
What is the difference between casting and conversion? Eric Lippert's comments in [this question](https://stackoverflow.com/questions/3166349/what-is-the-type-in-typeobjectname-var) have left me thoro...
- Modified
- 23 May at 12:34
What's wrong with casting 0.0 to double?
What's wrong with casting 0.0 to double? I have `InvalidCastException` when I try to cast 0.0 to double, why is that so? It's fine when I do `(float)value` instead. ![alt text](https://i.stack.imgur.c...
Fastest way to convert string to integer in PHP
Fastest way to convert string to integer in PHP Using PHP, what's the fastest way to convert a string like this: `"123"` to an integer? Why is that particular method the fastest? What happens if it ge...
- Modified
- 27 Oct at 05:21
How to convert string to boolean php
How to convert string to boolean php How can I convert string to `boolean`? it returns, > boolean true but it should be `boolean false`.
Hive cast string to date dd-MM-yyyy
Hive cast string to date dd-MM-yyyy How can I cast a string in the format 'dd-MM-yyyy' to a date type also in the format 'dd-MM-yyyy' in Hive? Something along the lines of:
C convert floating point to int
C convert floating point to int I'm using (not C++). I need to convert a float number into an `int`. I do not want to round to the the nearest number, I simply want to eliminate what is after the inte...
- Modified
- 13 Jul at 13:44
Why can't I cast DateTime[] to object[]?
Why can't I cast DateTime[] to object[]? It seems that I can cast DateTime to object, so why can't I cast array DateTime[] to object[]? I know this has something to do with value/reference types, but ...
Why cannot cast Integer to String in java?
Why cannot cast Integer to String in java? I found some strange exception: How it can be possible? Each object can be casted to String, doesn't it? The code is: Thanks.
How to cast ArrayList<> from List<>
How to cast ArrayList from List Can somebody please explain me why I can't cast `List` to `ArrayList` with first approach and I do with second one? Thank you. First approach: Second approach:
Cast to a reflected Type in C#
Cast to a reflected Type in C# Consider the following code: Do I need to do some magic with `typeFoo` to get the result?
- Modified
- 5 Aug at 08:2
What's the C# equivalent to C++'s dynamic_cast?
What's the C# equivalent to C++'s dynamic_cast? This C++ code checks if `o` is a `Node *` and if so, calls a method on `d`. What's the shortest and/or most efficient way to write the equivalent in C#?
Cast List<int> to List<string> in .NET 2.0
Cast List to List in .NET 2.0 Can you cast a `List` to `List` somehow? I know I could loop through and .ToString() the thing, but a cast would be awesome. I'm in C# 2.0 (so no [LINQ](http://en.wikiped...
Casting an out-of-range number to an enum in C# does not produce an exception
Casting an out-of-range number to an enum in C# does not produce an exception The following code does not produce an exception but instead passes the value 4 to tst. Can anyone explain the reason behi...
Is it possible to assign a base class object to a derived class reference with an explicit typecast?
Is it possible to assign a base class object to a derived class reference with an explicit typecast? Is it possible to assign a base class object to a derived class reference with an explicit typecast...
- Modified
- 14 Jul at 20:21
Is using "as" in C# a safe way of casting?
Is using "as" in C# a safe way of casting? I am wondering if using the keyword "as" in the following code is a safe way (i.e. won't blow up) of casting in C#: Is there a safer way of casting?