I am getting a practical issue and the issue can be dascribed as follows.
We are developing a component (Say a plugin) to do some task when an event is triggered within an external CMS using the API provided by them. They have provided some jar libraries, So what we are doing is implementing an Interface provided by them. Then an intern...
How do I cast a parameter passed into a function at runtime?
private object PopulateObject(object dataObj, System.Data.DataRow dataRow, string query)
{
object = DataAccess.Retriever.RetrieveArray<dataObj.GetType()>(query);
i'd like to know how to get dataObj.GetType() inside the type declaration at runtime.
...
Basically what I want to do is, depending on the some variable, to cast a void pointer into a different datatype. For example (the 'cast' variable is just something in order to get my point across):
void* ptr = some data;
int temp = some data;
int i = 0;
...
if(temp == 32) cast = (uint32*)
else if(temp == 16) cast = (uint16*)
el...
I'm dealing with financial data, so there's a lot of it and it needs to be relatively high-precision (64bit floating point or wider).
The standard practice around my workplace seems to be to represent all of it as the c# decimal type which is a 128bit wide floating point specifically created to support round-off free base10 operations.
...
I want to write a generic class that should be casted to itself with a different generic argument.
class Base {}
class Inherited : Base {}
class MyGeneric<T> {}
// WCF Service interface
void Foo(MyGeneric<Base> b);
// somewhere else
MyGeneric<Inherited> inherited;
Foo(inherited)
I know that this could be done in C# 4.0, but this do...
I have to following code in VS2008 .net 3.5 using WinForms:
byte percent = 70;
byte zero = 0;
Bitmap copy = (Bitmap)image1.Clone();
...
Color oColor = copy.GetPixel(x, y);
byte oR = (byte)(oColor.R - percent < zero ? zero : oColor.R - percent);
When I leave the "(byte)" off the last line of code, I get a compiler error saying it "Ca...
For example, lets say you have two classes:
public class TestA {}
public class TestB extends TestA{}
I have a method that returns a List<TestA> and I would like to cast all the objects in that list to TestB so that I'd end up with List<TestB>.
...
I got a typical 'vector4' class with an operator float* to autocast it for gl*4fv as well as [].
There's also 'const' version for optimizations for the compiler as well as const refrences, and this works fine:
typedef struct vec4
{
...
// ----------------------------------------------------------------- //
// Cast operator, for []...
I've moved to a new webhost were we have php 5.1 instead of 5.2 that I've been using until now. I still haven't figured out if it's a php version or configuration issue.
Right now most (or all) of the classes that have __toString functions convert to "Object ID #" (like in php4) but before they all returned the correct values.
How can ...
I need to downcast a long to an int in a method where the long is passed as a ref variable:
public void Foo(ref long l)
{
// need to consume l as an int
}
How can I easily do this?
...
Suppose I have the following code:
void* my_alloc (size_t size)
{
return new char [size];
}
void my_free (void* ptr)
{
delete [] ptr;
}
Is this safe? Or must ptr be cast to char* prior to deletion?
...
I have a legacy SQL Server 2000 database that has one column that has a date that is stored as a varchar instead of a datetime for whatever reason. I want to make a view against this data and use a datetime field instead of a varchar to make making a report against the field easier. The good news is that most of the values look like th...
I wanted to ask about the following case:
char *temp;
temp=malloc(10);
Since the return type of malloc is void, will the pointer returned by the malloc be implicitly cast to char type before being assigned to temp? What does the standard say in this regard?
If our pointer variable is some struct type for ex.
struct node *temp;
temp...
Hi guys,
I want to convert dateformat to mm/dd/yyyy. Whatever dateformat is coming in textbox, I want to convert it into mm/dd/yyyy. Can anybody help?
...
Possible Duplicate:
What is the difference between the following casts in c#?
In C#, is a there difference between casting an object or using the as keyword? Hopefully this code will illustrate what I mean...
String text = "Hello hello";
Object obj = text;
String originalCast = ((String)obj).ToUpper();
String originalAs = (ob...
Hey everyone, I'm new to persistence / hibernate and I need your help.
Here's the situation. I have a table that contains some stuff. Let's call them Persons.
I'd like to get all the entries from the database that are in that table.
I have a Person class that is a simple POJO with a property for each column in the table (name, age,..)
...
This sounds like a simple one but I can't find the solution anywhere.
How do you cast objects in cocoa objective c for the iPhone?
I'm trying to get the length of a string in an nsuinteger object like so:
NSUInteger *phoneNumberLength = [phoneNumber length];
I get the warning initialization makes pointer from integer without...
Hi,
in a ASP.NET application (MVC) I have a foreach loop that loops through a structure that may contain or not some element:
<% foreach (XElement segnalazione in ((XElement)ViewData["collezioneSegnalazioni"]).Elements("dossier")) { %>
<tr>
<td><%= Html.Encode(segnalazione.Element("NUM_DOSSIER").Val...
I am wondering which is more efficient, using CStr() or object.toString().
The reason I ask this is because I though all that CStr() done was to invoke the .ToString() method on the object it was dealing with.
But when recently using a generic method without any type constraints I had to use object.ToString() instead of CStr(object), th...
If I have an instance of class B which is a subclass of class A, is there a way for me to turn my instance of class B into an instance of class A without explicitly writing code to do it?
I do not mean simply downcasting with the standard c syntax.
...