Every time I think I understand about casting and conversions, I find another strange behavior.
long l = 123456789L;
float f = l;
System.out.println(f); // outputs 1.23456792E8
Given that a long has greater bit-depth than a float, I would expect that an explicit cast would be required in order for this to compile. And not surprising...
I have a LINQ query to retrieve the maximum value of an integer column. The column is defined as NOT NULL in the database. However, when using the MAX aggregate function in SQL you will get a NULL result if no rows are returned by the query.
Here is a sample LINQ query I am using against the Northwind database to demonstrate what I am d...
I keep finding both on here and Google people having troubles going from long to int and not the other way around. Yet I'm sure I'm not the only one that has run into this scenario before going from int to Long.
The only other answers I've found were "Just set it as Long in the first place" which really doesn't address the question.
Ca...
I want to reinterpret cast a function pointer into a void* variable. The type of the function pointer will be of type Class* (*)(void*).
Below is the sample code,
class Test
{
int a;
};
int main()
{
Test* *p(void **a);
void *f=reinterpret_cast<void*>(p);
}
The above code works well with Visual Studio/x86 compilers. B...
If I have a method that passes an argument of type void * (UIView animation did stop method, has to be a void pointer), or of type id, and I know that the argument is a UIBarButton item, and I need to disable it, [barbuttonitem setEnabled:NO];, should I cast the argument to a UIControl, which is as far as I need to be able to use setEnab...
I'm working on a legacy classic ASP interface between our client application and the server. This is not a website, just an intermediate layer in ASP (I know this is not the preferred way of doing things, told you it's legacy and it can - unfortunately - not be changed at this point).
So I'm sending a double value as a parameter on the ...
Hello Everyone,
I have a property that returns an interface. During debugging I can break on what was returned and while it is the interface, Visual Studio is smart enough to know the derived type that it actually is. I assume it's using reflection or something. I'm not sure. My question is, can I have that same info avaialble to me at r...
Is it possible to cast out param arguments in C#? I have:
Dictionary<string,object> dict; // but I know all values are strings
string key, value;
Roughly speaking (and if I didn't have static typing) I want to do:
dict.TryGetValue(key, out value);
but this obviously won't compile because it "cannot convert from 'out string' to 'o...
Hi,
Is there some tool that can automatically convert the following c style code
A *a = b;
to
A *a = (A*)b;
Thanks,
James
...
Hi,
I've read the topic about passing an object[] to a params object[] but I don't know why it's not working with me.
I have these too functions in a class:
...
private void CallbackEvent(object source, CallbackEvetArgs e) { // Some event with e.Data as string
...
string[] values = e.Data.Split('|');
DoSave("s...
Hi everyone,
i was just wondering if anyone knows how to select rows where a specified column will come under a casting issue.
ie.
SELECT * FROM ThisTable t
WHERE 0 <> ( select cast(t.value as
datetime) )
the 'select cast(t.value as datetime)' would ideally return the result of @@error
to indicate the casting issue has oc...
When is it safe to use implicit casting?
Use Case: I'm working with a set of com objects that need to be taken care of specially (Marshal.ReleaseComObject). Is it OK to create a wrapper class that implicitly converts back to the actual com object wrapped?
What are some situations when I shouldn't use implicit casting?
...
Hi there,
I need an sql query to give me the following:
All the values in a column of type varchar(50) which will NOT convert or will throw an error if cast / converted to an int.
E.g.
row 1: '1'
row 2: '2'
row 3: '3a'
row 4: '4.5'
I need row 3....however there are tens of thousands of rows.
Thanks!
...
Hey there!
I have an object with a Property of type byte[,,*]
now i'd like to use System.Random::NextBytes() to fill this multidimensional array with random values.
NextBytes however takes an argument of byte[]
can i cast the multidimensional array somehow to the singledimensional one in order to pass it as an argument?
thanks!
...
This one has proven to be a little tricky for me so far. I am wondering if it is possible to type cast an object using a System.Type object.
I have illustrated below what I mean:
public interface IDataAdapter
{
object Transform(object input);
Type GetOutputType();
}
public class SomeRandomAdapter : IDataAdapter
{
public ob...
So, I have some code that looks approximately like (truncated for brevity - ignore things like the public member variables):
public class GenericThingy<T> {
private T mValue;
public final T[] mCandidates;
public GenericThingy(T[] pCandidates, T pInitValue) {
mCandidates = pCandidates;
mValue = pInitValue;
...
I have a base class, say Base which specifies the abstract method deepCopy, and a myriad of subclasses, say A, B, C, ... Z. How can I define deepCopy so that its signature is public X deepCopy() for each class X?
Right, now, I have:
abstract class Base {
public abstract Base deepCopy();
}
Unfortunately, that means that if if I have...
When I try to get the sum of a column from a table I get the error 'Arithmetic overflow error converting expression to data type int' because the resulting number is to big for an INT. So I tried to CAST to a BIGINT using
SELECT CAST(SUM(columnname) AS BIGINT) FROM tablename
but I get the same error. Any ideas what i'm doing wrong?
...
What is the most efficient way of converting a single column linq query to a string array?
private string[] WordList()
{
DataContext db = new DataContext();
var list = from x in db.Words
orderby x.Word ascending
select new { x.Word };
// return string array here
}
...
Basically a button's tag property is the name of an existing combobox which I need to dynamically reference. It's a generic function to handle multiple buttons. Help
private void SQLButton(object sender, EventArgs e)
{
magic(((Button)sender).Tag.ToString());
}
private void magic(string currentcombo)
{
string CurrentText = (Comb...