|
Yeah here's another way:
int number = enum as int;
XD
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
The Undefeated wrote: int number = enum as int;
that will not be accepted, for one "as" requires a reference type, not a value type.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
*shakes fist angrily at Luc*
You ruin everything
int Waffle(ref Enum myEnum)
{
return myEnum as int;
}
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
no no.
Error: The as operator must be used with a reference type ('int' is a value type)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
*cries*
Perhaps if i actually tried to use the code before i posted it.
*cries some more*
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
Yeah, the sensible sequence is:
- try to understand the problem at hand
- read the documentation
- try a couple of things
- search for a solution for the remaining problems
- only then post at CodeProject
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Ninja-the-Nerd wrote: what the heck does the (Int32) prefix do? Is it some sort of implicit conversion?
No, it's an explicit conversion.
An implicit conversion is when the conversion is done without specifying the data type, this is allowed when widening types, like from a byte to an int. Example:
byte data = 42;<br />
int moreData = data;
An explicit conversion is when you specify the data type. This is used to tell the compiler that you want the conversion eventhough the compiler doesn't know if it will always work, or when an implicit conversion isn't allowed, like with an enum. Example:
int data = 42;<br />
byte lessData = (byte)data;
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
I think a slightly better solution in this case is to use the int type rather than the Int32 object.
I have not really used the Int32 object but I assume that it acts in the same way as other objects in that it passes itself by reference instead of value. This may then catch out other developers who are used to integers being value types and not objects.
Instead use:
<br />
TestEnum te = new TestEnum();<br />
<br />
int enumNumber = (int) te;
Hope this helps.
|
|
|
|
|
MCEdwards wrote: I think a slightly better solution in this case is to use the int type rather than the Int32 object.
There is no difference.
MCEdwards wrote: I have not really used the Int32 object
Yes, you have. The int keyword is an alias for the System.Int32 data type.
MCEdwards wrote: I assume that it acts in the same way as other objects in that it passes itself by reference instead of value.
Assume away...
Int32 is a structure, not a class, so it's a value type, not a reference type.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
I have dataset that the row count of that dataset is more than 2 lackh. ijn waht way should i split my large dataset into two data set.
Yogesh Pekhale
pekhaleyogesh@gmail.com
|
|
|
|
|
You have to split the dataset? Can't you create instead two from origin? It would be better... Now, the first thing coming into my head is make a select on datatable to get few rows...
Visit my blog at http://dotnetforeveryone.blogspot.com
|
|
|
|
|
I want to display the values of Application variable of ASP.NET webpage into window application's listView control when I send httpRequest to that page.
|
|
|
|
|
hello sir,
I have a problem while developing an appliation in which i have to send http request to server and then receive response from server
please help me
|
|
|
|
|
|
Does this[^] article help?
/ravi
|
|
|
|
|
I .Net Framework 2 there is a very useful calls called the System.Net.WebClient class. This class contains methods that allow you to quickly make http and https requests and process the return. You can set headers and post information. I have used it to create a http post to remote servers and receive a response. Here is some code:
<br />
Byte [] PostData = System.Text.Encoding.ASCII.GetBytes("hello world");<br />
System.Net.WebClient client = new System.Net.WebClient();<br />
Byte[] Response = oClient.UploadData("http://www.somewhereintheworld.com", "POST", PostData);<br />
return System.Text.Encoding.ASCII.GetString(Response);<br />
These first line just turns the post data I want to send into a byte array. I create the WebClient object on the second line and then on the third line I tell the client to send the data to the target website as a post action with the byte array I have created. This returns a byte array that I then need to turn back into a string which is done on the last line.
Happy browsing.
|
|
|
|
|
Hello!!
I want to convert .bmp image to Jpeg image in C#. so kindly help me out.
thx
B!z
|
|
|
|
|
Snippet:
Image objImage = Image.FromFile("test.bmp"); <br />
objImage.Save("test_output.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
|
|
hi i'm Rajakumar, i'm doing a project c#. in that my application contains datas in two data grids, consider 3 rows and 3 columns each. i've to read those data and have to store in another datagrid but i couldn't able to read those data for multiply.
please can anyone help me to solve this problem.
my mail id is rj.rajakumar@gmail.com
|
|
|
|
|
Why are you storing in another data grid? Why not just put the data into an array and work from there?
"I really like comments where I don't have to answer stupid questions" - stfx
|
|
|
|
|
In articles/books i have method convert color image to grayscale.
This is the method :
ImageGrayscale=(Red+Green+Blue)/3
but i don't understand to convert bit image pixel to integer.
so, please help me to apply this method in C# language programming.
Thanks
Haloha...!!!!
|
|
|
|
|
Hi,
the Image class gives each pixel a Color value, which is basically a 32-bit number
(4 bytes, for alpha,red,green,blue). To make it a grayscale image, you should make
sure all pixels have no color by giving them the same value for red, green and blue.
So basically you could do (pseudocode!):
foreach (pixel pix in image) {
int gray=(R+G+B)/3;
pix.color=new color(gray,gray,gray);
}
For normal sized images this would be rather slow, you could consider using pointers.
Remark: CodeProject holds a good series of articles on image operations by Christian Graus.
You may want to read these.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
That method is wrong. To get good greyscale, you need to weight the pixels according to how our eyes work.
My image processing articles include a greyscale filter, but you can also do it far easer with a color matrix, there are plenty of examples online. My article answers your questions, tho.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
foreach(FileInfo file in files) {
}
you need to declare a type for thw variable 'file'
which could also be a string, or something else depeneding on what 'files' contains.
-- modified at 7:56 Friday 26th October, 2007
Dammit, i hate when people delete topics. It just leave posts floating around.
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
The Undefeated wrote: Dammit, i hate when people delete topics. It just leave posts floating around.
Not to mention it is very inconsiderate to other members. Someone may have the same question, and it had been answered. But they will never know because the question was deleted. Not that it matters, most people don't search articles, the forums, or google anyways.
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|