|
Hello!
I´m new to C# and have a question for the pro's.
Is it possible to put an ArrayList into another ArrayList like a 2d array?
How would the code look like?
Regards.
stumpi
|
|
|
|
|
ArrayList list1 = new ArrayList();
ArrayList list2;
for (int i=0; i< 2 ;++i)
{
list2 = new ArrayList();
list2.Add(i);
list1.Add(list2);
}
|
|
|
|
|
Not sure if this is a stupid problem.
I have a C# ASP.NET app that is consuming web services from third party product.
Problem is this third party prog is using some odd formats for passing back certain types.
Examples
A bool value will return either “true” or <null>
A date/time stamp will have the letter “T” inserted in the string before the time component.
.NET’s default SOAP interpretation is having problem with these types and the third party product is kind of a black box.
Sticking in an override for handling of these types at the .NET end would be ideal, but I’m kind of shooting blind on where to start.
Has anyone run across an issue like this before?
WR
|
|
|
|
|
Have a look around the net/CodeProject/MSDN for information on SOAP Extensions. These allow you to do various things with SOAP packets before and after serialization and deserialization.
If you have, or can lay hands on "Developing XML Web Services and Server Components with Visual Basic .NET and Visual C# .NET" (ISBN 0-7356-1586-1) they are explained on page 446.
Failing that use these keywords:
AfterDeserialize
AfterSerialize
BeforeDeserialize
BeforeSerialize
SoapExtension
I realize this is only a push in the right direction, but it is a large-ish topic.
Cheers, Steve
|
|
|
|
|
How can i get all the relavant info from an MP3 file using C#?
like the ID3 tag and the other MPEG info?
And also how can i edit it?
VisionTec
|
|
|
|
|
This is not perfect but it works.
<br />
<br />
namespace id3 {<br />
<br />
using System;<br />
using System.IO;<br />
using System.Text;<br />
<br />
class FileCommands <br />
{<br />
<br />
public static void GetMP3Tag (ref MP3 paramMP3) <br />
{<br />
try<br />
{<br />
FileStream oFileStream;<br />
oFileStream = new FileStream(paramMP3.fileComplete , FileMode.Open);<br />
byte[] bBuffer = new byte[128];<br />
oFileStream.Seek(-128, SeekOrigin.End);<br />
oFileStream.Read(bBuffer,0, 128);<br />
oFileStream.Close();<br />
<br />
Encoding instEncoding = new ASCIIEncoding();
string id3Tag = instEncoding.GetString(bBuffer);<br />
<br />
<br />
<br />
if (id3Tag .Substring(0,3) == "TAG") <br />
{<br />
paramMP3.id3Title = id3Tag.Substring( 3, 30).Trim();<br />
paramMP3.id3Artist = id3Tag.Substring( 33, 30).Trim();<br />
paramMP3.id3Album = id3Tag.Substring( 63, 30).Trim();<br />
paramMP3.id3Year = id3Tag.Substring( 93, 4).Trim();<br />
paramMP3.id3Comment = id3Tag.Substring( 97,28).Trim();<br />
<br />
<br />
<br />
if (id3Tag[125]==0)<br />
paramMP3.id3TrackNumber = bBuffer[126];<br />
else<br />
paramMP3.id3TrackNumber = 0;<br />
<br />
paramMP3.id3Genre = bBuffer[127];<br />
paramMP3.hasID3Tag = true;<br />
}<br />
else <br />
{<br />
paramMP3.id3Title = paramMP3.fileFileName.Substring(0,paramMP3.fileFileName.LastIndexOf("."));<br />
paramMP3.id3Artist = "";<br />
paramMP3.id3Album = "";<br />
paramMP3.id3Year = "";<br />
paramMP3.id3Comment = "";<br />
paramMP3.id3TrackNumber = 0;<br />
paramMP3.id3Genre = 0;<br />
paramMP3.hasID3Tag = false;<br />
}<br />
}<br />
catch<br />
{<br />
paramMP3.id3Title = paramMP3.fileFileName.Substring(0,paramMP3.fileFileName.LastIndexOf("."));<br />
paramMP3.id3Artist = "";<br />
paramMP3.id3Album = "";<br />
paramMP3.id3Year = "";<br />
paramMP3.id3Comment = "";<br />
paramMP3.id3TrackNumber = 0;<br />
paramMP3.id3Genre = 0;<br />
paramMP3.hasID3Tag = false;<br />
}<br />
}<br />
<br />
public static void UpdateMP3Tag (ref MP3 paramMP3) {<br />
paramMP3.id3Title = paramMP3.id3Title.Trim();<br />
paramMP3.id3Artist = paramMP3.id3Artist.Trim();<br />
paramMP3.id3Album = paramMP3.id3Album.Trim();<br />
paramMP3.id3Year = paramMP3.id3Year.Trim();<br />
paramMP3.id3Comment = paramMP3.id3Comment.Trim();<br />
<br />
if (paramMP3.id3Title.Length > 30) paramMP3.id3Title = paramMP3.id3Title.Substring(0,30);<br />
if (paramMP3.id3Artist.Length > 30) paramMP3.id3Artist = paramMP3.id3Artist.Substring(0,30);<br />
if (paramMP3.id3Album.Length > 30) paramMP3.id3Album = paramMP3.id3Album.Substring(0,30);<br />
if (paramMP3.id3Year.Length > 4) paramMP3.id3Year = paramMP3.id3Year.Substring(0,4);<br />
if (paramMP3.id3Comment.Length > 28) paramMP3.id3Comment = paramMP3.id3Comment.Substring(0,28);<br />
<br />
byte[] tagByteArray = new byte[128];<br />
for ( int i = 0; i < tagByteArray.Length; i++ ) tagByteArray[i] = 0;
<br />
Encoding instEncoding = new ASCIIEncoding();
byte[] workingByteArray = instEncoding.GetBytes("TAG"); <br />
Array.Copy(workingByteArray, 0, tagByteArray, 0, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Title);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 3, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Artist);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 33, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Album);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 63, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Year);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 93, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Comment);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 97, workingByteArray.Length);<br />
tagByteArray[126] = paramMP3.id3TrackNumber;<br />
tagByteArray[127] = paramMP3.id3Genre;<br />
<br />
FileStream oFileStream = new FileStream(paramMP3.fileComplete , FileMode.Open);<br />
if (paramMP3.hasID3Tag)<br />
oFileStream.Seek(-128, SeekOrigin.End);<br />
else<br />
oFileStream.Seek(0, SeekOrigin.End);<br />
oFileStream.Write(tagByteArray,0, 128);<br />
oFileStream.Close();<br />
paramMP3.hasID3Tag = true;<br />
}<br />
<br />
}<br />
<br />
struct MP3 <br />
{<br />
public string filePath;<br />
public string fileFileName;<br />
public string fileComplete;<br />
public bool hasID3Tag;<br />
public string id3Title;<br />
public string id3Artist;<br />
public string id3Album;<br />
public string id3Year;<br />
public string id3Comment;<br />
public byte id3TrackNumber;<br />
public byte id3Genre;<br />
<br />
public override string ToString()<br />
{<br />
return id3Title;<br />
}<br />
public MP3(string path, string name) <br />
{<br />
this.filePath = path;<br />
this.fileFileName = name;<br />
this.fileComplete = path + "\\" + name;<br />
this.hasID3Tag = false;<br />
this.id3Title = null;<br />
this.id3Artist = null;<br />
this.id3Album = null;<br />
this.id3Year = null;<br />
this.id3Comment = null;<br />
this.id3TrackNumber = 0;<br />
this.id3Genre = 0;<br />
}<br />
} <br />
}<br />
<br />
<br />
Leon v Wyk
|
|
|
|
|
This is a purely theoretical question--I'm not even asking for help this time.
I've been working a bunch with some clever datastructures and I have found myself needing to provide Equals overrides so that when I use Contains a correct comparison is used to determine whether elements are inside a datastructure.
Anyway, when you override Equals, you have to override GetHashCode. Why exactly is this? Is it that the default Equals behavior involves comparison of hash numbers for the objects being compared? I always thought that the default Equals was just comparison of addresses. Maybe it's my java experience bubbling over.
On this topic, if we do not know exactly how Microsoft/.NET's default implementation of GetHashCode operates, when we write our own implementations of GetHashCode isn't it possible that we could... well... really muck things up? It just seems like we would want the same hashing behavior for ANY kind of object.
vir·tu·al re·al·i·ty
n. Abbr. VR
A computer simulation of a real or imaginary universe in which Microsoft APIs are thoroughly documented and behave in an entirely logical manner.
|
|
|
|
|
McClamm wrote:
Anyway, when you override Equals, you have to override GetHashCode. Why exactly is this?
Two identical objects (x.Equals(y) == true) should return the same hashcode. If you fail to do it, you won't be able to use this object as a key on a Hashtable. Think about the string class: two different string instances, with identical chars, are equal (x.Equals(y) == true), and they return the same GetHashCode(), so they can be used as a key on a Hashtable.
Often, when you override Equals, you simply compare a field (or a combination of fields). Simply return the hashcode of this field, and probably you're done.
Yes, even I am blogging now!
|
|
|
|
|
I am a new programmer in C#, so I hope there is an easy answer for this problem.
I need to declare an array of class objects, and the code compiles fine, but I always get the runtime exception "Object reference not set to an instance of an object." When I single step through the code, the exception is thrown when the array declaration statement is executed. I have tried the same declaration, but for a single instance rather than an array, and it works fine. I can step through the constructor and see that all the variable are created properly.
Below are the two statements that I have used. I try the array declaration, and it bombs. The single instance works great. Any suggestions on what I am doing wrong? I can provide more details if needed.
Parameter[] yearsArray = new Parameter[yearsOfData];
Parameter yearArray = new Parameter();
Steve
|
|
|
|
|
Steve Searcy wrote:
Parameter[] yearsArray = new Parameter[yearsOfData];
This declares an array. All items on the array are null (yearsArray[0], yearsArray[1]... yearsArray[yearsOfData]).
You need to assign new instances to them in a loop.
Yes, even I am blogging now!
|
|
|
|
|
hi
how to control in a datagrid header .....
i mean want to add aheader to group of columns
suppose u have "First Name","Last Name" headers and u want to group them under a toal header "Personal Information" for example..
does any one kow how to do that !!??
|
|
|
|
|
Hi All,
With my datagrid I want different Column Headers to have different Colors?
There are global settings e.g
tableStyle.HeaderFont = Color.Green;
but I'm after soming like :
tableStyle.Columns[1].HeaderFont = Color.Green;
tableStyle.Columns[2].HeaderFont = Color.Blue;
I'm using C#. I'm aware of 3rd Party tools that can do this, but want to avoid them if possible.
Any help would be very much appreciated,
Thanks, Jonny
|
|
|
|
|
Hi,
Is anyone know how to write automatic updates like windows automatic updates ?
Thank
|
|
|
|
|
|
Hi all,
i made a two combobox i fill the first one from database and i take the selected value from the first combobox to select another recorde from table but it got me an exception
"The column prefix 'System.Data' does not match with a table name or alias name used in the quer"
and this my code:
<br />
SqlDB DB = new SqlDB();<br />
DB.ConStr = DB.ConnectionSTR(DB.Current_DB());<br />
DataSet ds = DB.Select("Select * From MSA Where Client_ID = "+cboClient_Name.SelectedValue.ToString()+"");<br />
cboMSA_ID.DataSource = ds;<br />
cboMSA_ID.DisplayMember = "Table.MSA_Effective_Date";<br />
cboMSA_ID.ValueMember = "Table.MSA_ID";<br />
SqlDB contain the database handling (command , connection...)
please help
|
|
|
|
|
Does anybody know of any way to perform a string contains string check without using regex.
For example
string s1 = "abcdefg";
string s2 = "def";
string s3 = "xyz";
bool b1 = StringContains(s1, s2);
bool b2 = StringContains(s1, s3);
bool StringContains(string baseString, string searchString)
{
?????
}
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
Forget it, I just found the IndexOf() function
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
Hi gurus,
I have a simple question about formatting strings.
I would like to know how I can convert an hex value to the character itself?
we give the string "3a" and the formatting says ";".
how to do that in C#? the %x format is unknown to C#
thanks.
best regards.
There is no spoon.
|
|
|
|
|
Use int.ToString()
If you have : int a = 0x3a;
The result of a.ToString("X") is "3A"
Ami
|
|
|
|
|
thanks for the trick.
I use the Convert class
Convert.ToString(Convert.ToChar(int.Parse(txtCharacter.Text, System.Globalization.NumberStyles.HexNumber)));
It's heavy but it does what I want. If things can be simpler, let me know.
There is no spoon.
|
|
|
|
|
A little heavy? That's an understatement...
Like Ami said...
myInt.ToString("X")
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
what do you mean by "understatement"? you mean I've done the same in an other way?
There is no spoon.
|
|
|
|
|
The code you came up with is needlessly complex, doing multiple conversions that are both redundent and useless. Your code converted a text property to an int, back to a string, then broke that into an array of chars, then converted that back to a string again.
All you had to do is dive into the documentation on .ToString() and it would have made your life so much easier. It probably would have taken you the same amount of time to read that and come up with the correct answer to your problem as it did to try everything under the sun and come up with the bastardized statement you posted.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
It probably would have taken you the same amount of time to read that and come up with the correct answer to your problem as it did to try everything under the sun and come up with the bastardized statement you posted.
When there are 8,000+ classes (or whatever it's up to now) that probably happens more often than not to some degree.
- Nick Parker My Blog | My Articles
|
|
|
|
|
I developed a SMS application, I use a timer to pool the modem every now and then for new responses if a response is found I launch an ResponseReceived event, then that event looks for the type of response, then when a new message is detected I launch the NewMessageReceived event from the ResponseReceived event. The main application receives this event and opens a new dialog window, but the problem is that it does not show the window. I can see the window in the taskbar but not on the screen. I tried forcing the window to show, go topmost, maximize, every thing, but no window. I suspect that this could be due to threading of the timer or something, can anyone help?
Leon v Wyk
|
|
|
|
|