|
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
|
|
|
|
|
You should be able to send data quickly enough. I have an application that does something similar (turns many flags and less than full byte variables into a bit array in 'real time') and it keeps up.
For fields larger than 8 bits, just use the BitConverter class to get a variable of the next size up (eg: ushort for 10 bits, uint for 20 bits) and apply the same masking and combination techniques. Also, I would OR values together instead of adding them.
|
|
|
|
|
|
Hi,
is there a way to split the picturBox on demand, so that only everything underneath the diagonal is usable to paint on it?
|
|
|
|
|
Hell, no. A picturebox is a close to useless control, it's only value is to draw pictures for people too inexperienced to handle their own paint event. If you draw it yourself, you can use an ImageAttributes object in a DrawImage overload of the Graphics class, to specify a color range that would be transparent. This would occur in the Paint event.
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.
|
|
|
|
|
Hi Christian,
thanks for your answer. Like i said in the other thread, i unfortunately can't use something else than a picturebox.
Maybe i can draw a graphic(in my case a triangle) in the pb-paint event and set it to be always in the foreground or something like that?!
It's only important that a part of the pb seems to be empty no matter if there was something painted or written.
|
|
|
|
|
Oh, I thought you wanted to disable the bikini on a model.
|
|
|
|
|
hehe good idea but not my intention.
I'm thankfull for any suggestion.
|
|
|
|
|
ok i think i found the solution and yes it is possible
picturebox.setclip should do the work for me. Now im gonna try it...
|
|
|
|