Hello folk,
I need to detect if a flag is set within an enum value, which type is marked with the Flag attribute.
Usually it is made like that:
(value & flag) == flag
But since I need to do this by generic (sometimes at runtime I event have only an "Enum" reference. I can not find an easy way to use the & operator. At the moment I m...
I have these Arrays
//Array elements are Sprites (Class) in Flash Library
var elements:Array = new Array (el1_spr, el2_spr, el3_spr);
var container:Array = new Array();
for var (i:uint; allElements.length; i++){
container.push(allElements[i]);
var v:Sprite = (allElements[i] as Sprite);
addChild(conta...
Would it be correct to say that whenever casting is used, the resulting object is a
const object?
...And therefore can only be used as an argument to a function if that
function accepts it as a const object?
e.g.
class C1 {
public: C1(int i=7, double d = 2.5){};
};
void f(C1& c) {};
int main(){
f(8);
return 1;
}
//won't...
Hi all,
I have a void pointer returned by dlsym(), I want to call the function pointed by the void pointer.
So I do a type conversion by casting:
void *gptr = dlsym(some symbol..) ;
typedef void (*fptr)();
fptr my_fptr = static_cast<fptr>(gptr) ;
I hav also tried reinterpret_cast but no luck, although the C cast operator seems to work...
Hi All,
I have one doubt regarding casting.
public void Test(out T a, out T b)
{
object d,e;
d = 10;
e = 35;
Console.WriteLine(d.GetType());
a = (T)d;
b = (T)e;
}
Here d.getType() will return System.int32. so my question is why cant we directly code something like a=(T)10;
I...
I have the following scenario where I want to pass in string and a generic type:
public class Worker {
public void DoSomeWork<T>(string value)
where T : struct, IComparable<T>, IEquatable<T> { ... }
}
At some point along the way I need to convert the string value to its T value. But I don't want to do a straight convert a...
What's wrong with the following code?
Object[] a = new Object[1];
Integer b=1;
a[0]=b;
Integer[] c = (Integer[]) a;
The code has the following error at the last line :
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
...
Hey everyone,
I'm getting an IllegalCastException on the following (see bold line):
public void renderXML(final String xml) {
final Document xmlDoc = XMLParser.parse(xml);
final com.google.gwt.xml.client.Element root = xmlDoc.getDocumentElement();
XMLParser.removeWhitespace(xmlDoc);
final NodeList collection = root.getElementsByTa...
I defined a Java interface to represent the ability of an object to copy itself (no, I don't want to use Cloneable, but thanks for the suggestion ;-). It's generic:
public interface Copiable<T> {
T copy();
}
An object will only make copies of its own type:
public class Foo implements Copiable<Foo> {
Foo copy() { return new Fo...
Below is the code snippet that I am using.
using System;
using System.Collections.Generic;
using System.Text;
namespace businessTMS
{
public class SignIn
{
public string authenticate(String UserName, String password)
{
dataTMS.SignIn data = new dataTMS.SignIn();
string authenticate=(strin...
I want to upcast object array to different array of different object type like below
object[] objects; // assuming that it is non-empty
CLassA[] newObjects = objects as ClassA[]; // assuming that object to ClassA is valid upcasting
is there any way other than upcasting each element individually?
...
I have the following inheritance:
internal abstract class TeraRow{}
internal class xRow : TeraRow {} // xRow is a child of TeraRow
public IEnumerable<TeraRow> Compare(MappedTables which, DateTime selectionStart
, DateTime selectionEnd, string pwd)
{
IEnumerable<xRow> result=CompareX();
return (IEnumerable<TeraRow>)result; /...
Hi
Just like we do with __ToString, is there a way to define a method for casting?
$obj = (MyClass) $another_class_obj;
...
Hello,
I have a string in PHP (came from some data source), which represents a formatted unsigned 32-bit integer.
I need to store it into a MySQL database as a signed 32-bit integer, so that later I can retrieve it from PHP and use it as a (possibly negative) signed integer constant (since PHP doesn't have unsigned integers).
So, what ...
Problem: I cannot understand the number 256 (2^8) in the extract of the IBM article:
On the other hand, if it's a
big-endian system, the high byte is 1
and the value of x is 256.
Assume each element in an array consumes 4 bites, then the processor should read somehow: 1000 0000. If it is a big endian, it is 0001 0000 because en...
What happens if I cast a double to an int, but the value of the double is out of range?
Lets say I do something like this?
double d = double(INT_MIN) - 10000.0;
int a = (int)d;
What is the value of a? Is it undefined?
...
We are developing a standalone application that stores its data in a Database. We use Dataset and TableAdapters for the communication with the Database. One of the basic requirements is the application to be able to use SQL Server, Oracle and MySQL. For this purpose we made the queries in the TAs vendor independent. We use ODBC provider....
Hello!
This isn't really an issue, however I am curious. When I save a string in lets say an DataRow, it is cast to Object. When I want to use it, I have to cast it ToString. As far as I know there are several ways of doing this, first is
string name = (string)DataRowObject["name"]; //valid since I know it's a string
and another one ...
Say I have a method that is expecting a generic collection parameter of a base type, see Test.MethodA(IEnumerable(BaseClass) listA) below. How come when I pass it a collection of a derived type the code wont build? Wouldn't all instances of DerivedClass also be a BaseClass?
I could have just created a new List(BaseClass) and passed that...
If I just write something like
select 10.00;
What type does this give me?
Here's a test I ran, to test the binary representation of these types. The big surprise here is that none of the casts actually match the first row!
select cast(123.866 as binary) union all
select cast(cast(123.866 as real) as binary) union all
select cas...