I have two classes, named Post and Question. Question is defined as:
public class Question : Post
{
//...
}
My Question class does not override any members of Post, it just expresses a few other ones.
What I want to accomplish
I have an object of type Post, whose members are populated. Now, I want to convert it into a Question, so...
The Data Model section of the Python 3.1 documentation provides the following descriptions for the __int__ and __index__ methods:
object.__int__(self)
Called to implement the built-in [function int()]. Should return a value of the appropriate type.
object.__index__(self)
Called to implement operator.index(). Also calle...
I have code:
public delegate int SomeDelegate(int p);
public static int Inc(int p) {
return p + 1;
}
I can cast Inc to SomeDelegate or Func<int, int>:
SomeDelegate a = Inc;
Func<int, int> b = Inc;
but I can't cast Inc to SomeDelegate and after that cast to Func<int, int> with usual way like this:
Func<int, int> c = (Func<int,...
Hello these,
This does not compile, any suggestion appreciated.
...
List<Object> list = getList();
return (List<Customer>) list;
Compiler says: cannot cast List<Object> to List<Customer>
...
I have a legacy database that has integer data stored as chars that I would like to treat as numerical. Is there a quick and easy way to convert this is one place? The values are from 0-5 and it defaults to 0 so there are no nulls.
I can't just fix the data because the legacy db will still be updated by the legacy app.
So I am basica...
What is the actual difference between a long and an int in C#? I understand that in C/C++ long would be 64bit on some 64bit platforms(depending on OS of course) but in C# it's all running in the .NET runtime, so is there an actual distinction?
Another question: can an int hold a long(by cast) without losing data on all platforms?
...
Not sure how to title this...
So I've got three child classes of Event: WeightEvent, TimedEvent, RepEvent. Through whatever means, I get an object of one of the children. Now I want to send that child event to a method in another object so it can pull the data from it with the getSavedEvents() method. The method only exists in the child...
Possible Duplicate:
Perfomance of TypeCasting
How expensive is it to cast as object as a another object?
CustomClass instance = GenericObject as CustomClass
Should it be avoided as all costs?
Wanting to see how others think about this. I'm sure it's very situational.
...
I have the following:
MyEnum? maybeValue = GetValueOrNull();
if (null != maybeValue)
{
MyEnum value = (MyEnum)maybeValue;
}
What I want to know is if that explicit (MyEnum) cast is necessary on an instance of type MyEnum?. This seems like a simple question, I just felt paranoid that there could possibly be some runtime error if ...
I am about to start working on something the requires reading bytes and creating strings. The bytes being read represent UTF-16 strings. So just to test things out I wanted to convert a simple byte array in UTF-16 encoding to a string. The first 2 bytes in the array must represent the endianness and so must be either 0xff 0xfe or 0xfe...
Why isn't a Map<String,List<SomeBean>> castable to Map<String,List<?>>?
What I'm doing now is this:
Map<String, List<SomeBean>> fromMap = new LinkedHashMap<String, List<SomeBean>>();
/* filling in data to fromMap here */
Map<String,List<?>> toMap = new LinkedHashMap<String, List<?>>();
for (String key : fromMap.keySet()) {
toMap....
Hello,
I was just reading about the bad practice of casting the return value of malloc. If I understood correctly, it is absolutely legal to leave the cast as it is done implicitly (and should be left, because of other problems it could generate). Well my question is, when should I then cast my values ? Is there some general rule or some...
Hi,
I'm in the process of porting an old excel addin that was writen in VBA to VB .NET. The Excel addin interacts with a number of external com objects. The code sorta looks like this:
Dim hurr as Object
Dim durr as String
hurr = CreateObject("COM Object")
durr = hurr.getString
What I'm trying to do is read the string from the COM o...
I have quite complicated set of HTML that I want to trawl looking for inputs that match various criteria. I hope to use something along the lines of:
private void setup()
{
masterContainer.InnerHtml = @"
<div>crazy
<div>unknown
<div>html layout
<select id='crazySelectIdentifier_id1' runat='ser...
I come across this code
int n1 = 10;
int n2 = (int &)n1;
I don't understand the meaning of this casting, n2 is not reference since modifying n1 doesn't reflect n1. Strangely this code throws compiler error in gcc where as compiles fine in VC++.
Anybody know the meaning of this casting?
...
Example code:
fac :: Int → Int
fac 0 = 1
fac n = n * fac (n-1)
main = do
putStrLn show fac 10
Error:
Couldnt match expected type 'String'
against inferred type 'a -> String'
In the first argument of 'putStrLn', namely 'show'
In the expression: putStrLn show fac 10
...
I'm trying to figure out the answer to this question with the following code, but it turns out, the value of the pointer (address of problem3 turned out to be so far away from the parameter and local variables of the function) where the hell is x = problem3; pointing to...
void problem3(int a) {
int overflowme[16];
int x = probl...
I'm hacking a security system DVR so I can add motion capture and other fun features in python (version 2.6). One of the functions I was able to decompile from java and convert to python was the following:
def ToInt(abyte0, i):
if(abyte0[i] >= 0):
j = abyte0[i]
print "A " + str(j)
else:
j = 256 + abyte0[i]
if a...
I need to cast a boolean as an object, or NSKeyedArchiver throws a memory access error. What's the best way to do this?
...
Hi,
I'm writing an MD3 model loader in C++ and I understand the file format and what I need to do but I can't seem to get the syntax right. I have a class for the model and within that class there are a set of structs which will have the model data read into them. In the implementation of the class there is a constructor which reads da...