I want to run a query to get a string array of distinct "logName" items for a logType. The following works great:
Dim stringArray() As String = (From item In dc.Vw_Logs
Where item.LogType = [Passed in logType]
Select item.LogName Distinct).ToArray()
However, this only works when a specific LogType is set. I would like the ...
I have two classes generated by LINQ2SQL both from the same table so they have the exact same properties.
I want to convert / cast a object to the other class. what's the easiest way to do this?
I know I can just manually assign each property, but that is a lot of code.
...
I'm trying to use a hardcoded 64bit integer in a string variable.
Simplfied I want to do something like this:
$i = 76561197961384956;
$s = "i = $i";
Which should result in s being:
i = 76561197961384956
This does obviously not work as PHP cast big integers to float, therefore s is:
i = 7.65611979614E+16
While several other meth...
I know that I can use implicit conversions with a class as follows but is there any way that I can get a instance to return a string without a cast or conversion?
public class Fred
{
public static implicit operator string(Fred fred)
{
return DateTime.Now.ToLongTimeString();
}
}
public class Program
{
static void...
When I have many controls on a Form (i.e. Label, Button etc) that do almost the same thing, I often use one method to handle all the controls Click, MouseDown, MouseUp events.
But to know which of the controls throwing the event and access the properties of that control I need to cast the "sender" object to the correct type.
The thing ...
C++ comes with four built-in casts.
static_cast
dynamic_cast
const_cast
reinterpret_cast
Not to meantion the frowned upon C (style*)cast.
Additionally boost supplies a lexical_cast, are there any other useful casts that you use or would like to exist?
...
ok I give up, how do you do this in one line?
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
//List<string> fields = values.ToList<string>();
//List<string> fields = values as List<string>;
//List<string> fields = (List<string>)values;
List<string> f...
I am using entity model with a SQL DB, and I have a set of about 30 lookup tables which are in the same 3 column format, ID,Text,IsActive. But rather than create 30 forms I would like to create one form and depending on the string name of a type given, then populate a gridview and allow ability to Insert,Update or Delete records of that ...
Hi all,
I am fairly new to c# and asp.net and am having an issue converting type;
My situation is that I have a search engine that has a textbox for the search text and two radio buttons for the search location ( IE City1 or City2 )
When I recieve the search text and radio buttons they are in the form of a string
IE
string thesearcht...
I created a Converter to convert from double to integer.
But the line "return (int)value;" always gets a "specified cast is not valid."
What do I have to do so that my Converter successfully converts a double and sends back an integer?
Converter:
namespace TestChangeAngle
{
[ValueConversion(typeof(double), typeof(int))]
class...
I have just come across a Casting Exception while using the Telerik RadGrid.
It occurs during the DataBind event if I have an array of objects as the datasource
radgrid1.DataSource = new BaseObject[] { new ChildObject1(), new ChildObject2() };
where the classes ChildObject1 and ChildObject2 both inherit from the class BaseObject.
...
I have an array of Castle windsor registration components of type IRegistration[]
In this case ComponentRegistration<T> : IRegistration
For each element in my array,
if it can be upcast to ComponentRegistration<> I would like to upcast it back to ComponentRegistration<T> and process it. How exactly would I do this?
I got as far as
...
To return a double, do I have to cast to double even if types are double?
e.g.
double a = 32.34;
double b = 234.24;
double result = a - b + 1/12 + 3/12;
Do I have to cast (double) ?
...
In the code base I'm working in there have a method that has the signature
Public Sub SetDropDownValue(Of T As Structure)(ByVal target As ListControl, ByVal value As Nullable(Of T))
The method I am writing is passed a parameter of type object.
How can I cast the object into something that can be passed into the SetDropDownValue metho...
I've read in several articles that
for reference types using IEquatable reduces the use of casting
Can someone kindly provide a convincing example.
Thanks
Clarry
...
I am quite comfortable with generics and such, but in this special case I have a question concerning the "Type safety: Unchecked cast from .. to .." warning.
Basically I have a List of Class objects and now I want to get a subset of these that implement a special interface but the resulting List should also have that special Type:
...
...
I'm parsing an XML file with the XmlReader class in .NET and I thought it would be smart to write a generic parse function to read different attributes generically. I came up with the following function:
private static T ReadData<T>(XmlReader reader, string value)
{
reader.MoveToAttribute(value);
object readData = reader.ReadCon...
Hi, I have a problem converting SWFLoader.content into a MovieClip instance while following (TheFlashCanon's excellent tutorial) on making a SWF communicate with Flex. The SWF loaded in question is compiled using Flash CS3 (using actionscript 3).
However, when I try to get the content of the SWFLoader and convert it into a MovieClip ins...
I know that I can assign a value specifically to a float by doing
float y = 4.5f;
I want to do the same thing, except as a byte. How do I do this? I've checked the MSDN documentation and cannot find anything related to this. Also, what is this called?
Thanks,
[Edit]
For clarity the code I'm using this on is
byte myByte = a==b?1:0;...
I read some articles written on "ClassCastException" but I couldn't get a good idea on that. Can someone direct me to a good article or explain it briefly.
...