|
Yes
Basically I have a propertyinfo and a datacolumn and want to populate the property with the content of row[0] of the datacolumn. I think Piebalds ChangeType will do the trick.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I dunno, something like: System.Convert.ChangeType ( typeof(x) , y ) ?
|
|
|
|
|
PIEBALDconsult wrote: ChangeType
thats the one, thank you very much, found the script
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I find it's the only worthwhile member of Convert.
|
|
|
|
|
How about the base64 things? Are they bad? I've used them in the past, but if you say it's better to write your own I'll rewrite those things of course
|
|
|
|
|
Possibly, haven't used them, and I don't like the choice of plus and minus as digits. Makes base64 math hard to read.
I wrote my own.
|
|
|
|
|
Ok thanks I'll keep that in mind
|
|
|
|
|
|
Sure, just write some code.
|
|
|
|
|
|
Unfortunately, your question betrays a level of ignorance of basic C# coding that makes us assume the code you're posting came from the web, and you have no idea what it does. Perhaps you should read a book as your introduction to C#.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
You're using the wrong container to start with. If you want to store name/value pairs, use a dictionary to do it, or create a struct to contain the values. If you used a dictionary, then you could use FNAME and LNAME as keys and look the values up by key.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
well I am not a core C# programmer. so dont know much about it as U guys.
I mainly work on Delphi.
Anyways,
I am getting this data back form Web Service in the Format Mentioned.
I can anyways Use String functions to Match and get Values, but just valted to know if there is anything Handy I can use.
In Delphi I can get values just by specifying the lable for the List member. Dont know with C#.
Your help will be appreciated.
Thanks.
Niks
|
|
|
|
|
OK - well, in the first instance, you can use the split method on the string class, so long as there's always one = sign in the string. Otherwise, you can use regex to split it up.
So
string s = "FNAME=fred";
string [] vals = s.Split("=");
vals[0] is now FNAME= and vals[1] is now fred. You could then pass these values into a dictionary for later lookup.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Yeah, that's what I'd probably do.
Or write a class (or struct) that will deserialize from the provided datastream.
|
|
|
|
|
Hi guys
I have this struct in C++.
<br />
struct image<br />
{<br />
x:4;<br />
y:4;<br />
color:8;<br />
grayscale:1;<br />
spare:7;<br />
}<br />
<br />
<br />
what is the equivalent in C#?
|
|
|
|
|
Hi,
AFAIK C# does not support bit fields like C and C++ do.
You could create a struct with the right number of bytes, and give it properties supporting getting and setting the individual fields.
BTW: if you were to use that from multiple threads, you would have to provide a lock!
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thank you for your reply.
I have already used byte and ushort variables with left shifting but the problem is I will have more then one variable in a byte or short variable
ex
byte xy = x << 4 + y;
sometimes I will have 3 or more variables in one.I am looking for ideas, what about p-invoke?, I haven't used it before.
|
|
|
|
|
This is part of the solution:
public struct image {
private byte xy;
private byte color;
private byte gray;
public int X {
get { return xy>>4;}
sey { xy=(value<<4) | (xy&0xF);}
}
etc.
}
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
modified on Monday, July 20, 2009 8:15 PM
|
|
|
|
|
[Flags]
public enum PizzaToppings
{
ExtraCheese = 1,
Pepperoni = 2,
ItalianSausage = 4,
AmericanSausage = 8,
Peppers = 16,
Mushrooms = 32,
Anchovis = 64,
Pineapples = 128
}
public class Pizza
{
private PizzaToppings toppings;
public PizzaToppings Toppings
{
get{ return toppings; }
set{ toppings = value; }
}
}
Pizza p = new Pizza();
p.Toppings =
PizzaToppings.ExtraCheese |
PizzaToppings.ItalianSausage |
PizzaToppings.Pepperoni;
|
|
|
|
|
pixels are necessarily pizza toppings
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I thought there was (for interop), using attributes, I just never have so I don't recall.
Maybe I'll investigate a little later.
|
|
|
|
|
All Google could turn up was using field offsets to have several byte variables at the same address, then a lot of SHIFT and AND and OR. But then it doesn't make sense to me to have such unions, why not calculate the aggregate byte right away, as I did in my example.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Look into
System.Runtime.InteropServices.StructLayoutAttribute
and
System.Runtime.InteropServices.FieldOffsetAttribute
[StructLayout(LayoutKind.Explicit)]
public class SYSTEM_INFO
{
[FieldOffset(0)] public ulong OemId;
[FieldOffset(4)] public ulong PageSize;
[FieldOffset(16)] public ulong ActiveProcessorMask;
[FieldOffset(20)] public ulong NumberOfProcessors;
[FieldOffset(24)] public ulong ProcessorType;
}
Edit: Oh, wait, that's in bytes, not bits.
|
|
|
|
|
An idea came up to my mind
This is not a working code, it's just for demonstration
<br />
<br />
class image<br />
{<br />
byte x;
byte y;
byte color;
byte grayscale;
byte spare;
<br />
public byte[] getImageByteArray()<br />
{<br />
byte byteArray[3];<br />
byteArray[0] = x<<4 +y;<br />
byteArray[1] = color;<br />
byteArray[2] = grayscale<<7 + spare;<br />
}<br />
}<br />
<br />
I don't know if this will be fine since I am communicating with a real time application, and I have large structs,I mean will this bit manipulation slow the process of sending data over 40ms intervals.
Edit:
Another problem raises when I have fields larger than 8 bits
modified on Tuesday, July 21, 2009 5:02 AM
|
|
|
|