Wrox Programmer Forums
|
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 24th, 2009, 06:21 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default Variables

Hi all,

I have this piece of code sourced of the internet:
Code:
structid3v2frameheader
{
char frameid[4]; 
unsigned long size; 
unsigned char flag1; 
unsigned char flag2;
};
I have tried to put this into c# but it doesn't like a) the frameid[4], the 4 being the specified length of that char, b) the unsigned variable, is there any equivalents i could use?

Thanks inadvance
__________________
Apocolypse2005, I'm a programmer - of sorts.
 
Old October 31st, 2009, 05:09 AM
Authorized User
 
Join Date: Oct 2004
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to C@uark
Default

There are couple things you can do here:

declare a managed array as so
char[] frameid = new char[4]; //and use the operator new to init, also rank specifier preceeds variable name in c#

or declare a fixed length buffer field as so
fixed char frameid[4];
__________________
Mike
 
Old November 12th, 2009, 10:12 AM
Authorized User
 
Join Date: Nov 2009
Posts: 26
Thanks: 1
Thanked 1 Time in 1 Post
Smile Try this!!!!

First problem:You should dynamically allocate memory for array of characters (not needed for a single character like "char a;").so you can use this code (As C@uark mentioned in previous quote):
Code:
char[] frameid = new char[4];
Second problem:in C# 2008 (not sure about other versions),we don't have keyword "unsigned".Instead,we use the character 'u' before the unsigned types.For example:
Code:
uint x=5;
This piece of code declares x as a variable of type unsigned int.In other words,'u' is a shorthand for "unsigned".

And about char we don't have unsigned char,because char's definition is:
Single Unicode character, stored as an integer between 0 and 65535.
This is a definition from book "Beginning Microsoft Visual C# 2008".
As you see,char is automatically unsigned!!

You should enter this code instead of whole:
Code:
struct id3v2frameheader
{
char[] frameid = new char[4]; 
ulong size;//ulong is used instead of unsigned long 
char flag1;
char flag2;
};
Erfan





Similar Threads
Thread Thread Starter Forum Replies Last Post
variables daniel.mihalcea Javascript 1 September 9th, 2008 07:06 PM
using variables webgrphx Classic ASP Basics 3 April 11th, 2007 06:46 PM
Global Variables in C# su C# 2 December 11th, 2006 06:18 PM
initializing variables vin_0x1 Classic ASP Components 2 April 16th, 2006 07:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.