type-conversion

Convert textbox text to integer

Hi, I need to convert the text in the textbox of my xaml code to an integer value in C#. I am using .NET 4.0 and Visual Studio 2010. Is there a way to do it in xaml tags itself or do i need to write a converter in C sharp. I tried the following but is not working: Convert.ToInt32(this.txtboxname.Text) Any help is much appreciated. Tha...

Best (safest) way to convert from double to int

I'm curious as to the best way to convert a double to an int. Runtime safety is my primary concern here (it doesn't necessarily have to be the fastest method, but that would be my secondary concern). I've left a few options I can come up with below. Can anyone weigh in on which is best practice? Any better ways to accomplish this that...

Best way to get integer part of the string "600sp"???

I have a string, say "600sp" from which I wish to obtain the integer part (600). If I do Integer.valueOf("600sp") I get an exception due to the non-numeric value "s" which is encountered in the string. What is the fastest cleanest way to grab the integer part? Thanks! ...

VB.NET ArrayList to List(Of T) typed copy/conversion

I have a 3rd party method that returns an old-style ArrayList, and I want to convert it into a typed ArrayList(Of MyType). Dim udc As ArrayList = ThirdPartyClass.GetValues() Dim udcT AS List(Of MyType) = ?? I have made a simple loop, but there must be a better way: Dim udcT As New List(Of MyType) While udc.GetEnumerator.MoveNext ...

Scala implicit type conversion and ==

Can anyone enlighten me as to why implicit type conversion does not work with ==? Example: class BitArray(l: Int, v: Long) { val length = l var value = v def ==(that: BitArray) = value == that.value def ==(integer: Long) = value == integer def +(that: BitArray) = new BitArray(length,value+that.value ) ...

Actionscript 3 loading external swf casting issue

Hi all, I'm having something of an issue with trying to load externally defined classes in actionscript 3.0. I believe this to be an issue with my understanding of the ApplicationDomain / LoaderContext classes, but even after going over the documentation and a couple of web searches I'm still stuck. Essentially what I want to do is load...

C Language - [copy in place] float* to char* and the reverse

I want to copy a float buffer into a char (byte) buffer without allocating memory for two separate buffers. In another words I want to use one buffer and copy in place. The Problem is that if I need a float buffer then in order to copy that to a char then I will need a char* pointer; If I were copying from float* to float* it would be ...

char* to float*

I want to write a function that unpacks a char* buffer to a float* buffer. The char* buffer was originally packed as floats to bytes. What is the best way to do this? I have implemented integers below. I have packed an array of 4 byte sized integers in a char* buffer. This is the function I used to unpack it and assign it to int*. voi...

how to convert the <T> to its base type for generic method?

Hi all I have a generic CRUD class to perform add, delete, select, create to my entity objects. one of them - Message has two derived classes - order_message , and report_message. My problem is that in my generic class, I need an objectset to perform crud ops, but objectset does not accept a derived class type, it only accept base cla...

Is this extension method to force a string into an integer or default to 0 redundant?

I needed a one-liner to convert a string to an integer, and if the string is anything invalid, then just set it to zero. So I made the following extension method, but I can imagine there is a system method to do this in one line. Is there another way to do this in one line without creating an extension method? using System; namespace ...

What's the origin of asking interviewees to manually parse a string as an int?

I'm wondering, what's the origin of asking interviewees to manually parse a string as an int? (without relying on any casting/type-conversion that may be built into the language). Is this a standard question, suggested from a book or list or something? Has anybody else here on SO gotten asked this particular question during an interv...

Sorting items in JQuery on a variety of attributes ...

I need to give users the functionality to sort a list of products based on several pre-selected field names. The products list is structured roughly like ... <span class="productList"> <div class="product"> <p><strong class="sortName">Title</strong></p> <p>Weight: <span class="sortWeight">3.50</span> pounds</p> <p>Price: <span ...

Most efficient Dictionary<K,V>.ToString() with formatting?

What's the most efficient way to convert a Dictionary to a formatted string. e.g.: My method: public string DictToString(Dictionary<string, string> items, string format){ format = String.IsNullOrEmpty(format) ? "{0}='{1}' " : format; string itemString = ""; foreach(var item in items){ itemString = itemString + St...

LINQ to SQL Invalid Cast Issue

Hello All, I'm getting an invalid cast exception but I'm not sure why, here is the list of my conversions. SQL -> VB.NET char(4) -> String varchar(50) -> String tinyint -> Integer char(1) -> Char bit -> boolean smallint -> Integer smallmoney -> Double int -> Integer datetime -> datetime Thanks in advance for your help ...

Checking if a type supports an implicit or explicit type conversion to another type with .NET.

Imagine you've been given two System.Type's and you want to determine if there is an implicit or explicit type conversion from one to the other. Without specifically checking for the static methods is there a built in method to determine that the type supports either or these conversions? I know this is a brief body to a question but ...

MYSQL PDO return type strange conversion

I have the following table definition in MYSQL CREATE TABLE IF NOT EXISTS `test_cases` ( `id` int(10) unsigned NOT NULL auto_increment, `exercise_id` int(10) unsigned NOT NULL, `author_id` int(10) unsigned NOT NULL, `input_1_value` varchar(255) default NULL, `input_2_value` varchar(255) default NULL, `input_3_value` varchar(...

printf prints the wrong values

Why do I get the wrong values when I print a int using printf("%f, myNumber) ? I don't understand why it prints fine with %d, but not with %f. Shouldn't it just add extra zeros? int a = 1; int b = 10; int c = 100; int d = 1000; int e = 10000; printf("%d %d %d %d %d\n", a, b, c, d, e); //prints fine printf("%f %f %f %f %f\n", a, b, c...

How to convert from BYTE* to QString?

I have a DATA_BLOB structure but I need to convert it to QString. How can I do this? ...

vbscript: convert unicode string to array of bytes

I have unicode string passed to vbscript procedure (not visual basic 6, but vbscript). I want to iterate unicode string char by char, get code for every symbol, truncate code to byte range [0..255] and create array of bytes. This way new array of bytes should be twice smaller in memory compared to original unicode string. I am going sa...

cast class into another class or convert class to another

my question is shown in this code i have class like that public class maincs { public int a; public int b; public int c; public int d; } public class sub1 { public int a; public int b; public int c; } public void methoda (sub1 model) { maincs mdata = new maincs(){a = model.a , b = model.b , c= model.c} ; /...