Click here to Skip to main content
15,907,687 members
Home / Discussions / C#
   

C#

 
GeneralWhy string is reference data type. Pin
Member 180659621-Apr-05 21:48
Member 180659621-Apr-05 21:48 
GeneralRe: Why string is reference data type. Pin
S. Senthil Kumar21-Apr-05 22:24
S. Senthil Kumar21-Apr-05 22:24 
GeneralRe: Why string is reference data type. Pin
Colin Angus Mackay21-Apr-05 23:58
Colin Angus Mackay21-Apr-05 23:58 
GeneralRe: Why string is reference data type. Pin
vims22-Apr-05 0:08
vims22-Apr-05 0:08 
QuestionFileStream Performance ? Pin
CiNN21-Apr-05 21:04
CiNN21-Apr-05 21:04 
Generalzooming in winforms. Pin
sreejith ss nair21-Apr-05 20:18
sreejith ss nair21-Apr-05 20:18 
GeneralLaplacian pyramids Pin
Christian Graus21-Apr-05 19:25
protectorChristian Graus21-Apr-05 19:25 
GeneralRe: Laplacian pyramids Pin
John Fisher22-Apr-05 8:27
John Fisher22-Apr-05 8:27 
QuestionHow to play repeadly the media file in full screen mode Pin
Lalit N Dubey21-Apr-05 19:20
Lalit N Dubey21-Apr-05 19:20 
AnswerRe: How to play repeadly the media file in full screen mode Pin
Christian Graus21-Apr-05 19:23
protectorChristian Graus21-Apr-05 19:23 
GeneralRe: How to play repeadly the media file in full screen mode Pin
Lalit N Dubey21-Apr-05 23:17
Lalit N Dubey21-Apr-05 23:17 
GeneralRe: How to play repeadly the media file in full screen mode Pin
Christian in a nice hotel in Singapore24-Apr-05 0:23
sussChristian in a nice hotel in Singapore24-Apr-05 0:23 
GeneralCasting multi dimensional arrays Pin
Esmo200021-Apr-05 19:14
Esmo200021-Apr-05 19:14 
GeneralRe: Casting multi dimensional arrays Pin
Christian Graus21-Apr-05 19:23
protectorChristian Graus21-Apr-05 19:23 
GeneralRe: Casting multi dimensional arrays Pin
Esmo200022-Apr-05 1:41
Esmo200022-Apr-05 1:41 
GeneralRe: Casting multi dimensional arrays Pin
S. Senthil Kumar22-Apr-05 2:44
S. Senthil Kumar22-Apr-05 2:44 
GeneralWeird class cast issue Pin
serious-sam21-Apr-05 17:18
serious-sam21-Apr-05 17:18 
Hi all,

I'm having a problem using class casts. I'm storing an ArrayList inside a DataTable, and when I want to retrieve the list, I get an InvalidCastException. Here is my code:

using System;<br />
using System.Data;<br />
using System.Collections;<br />
<br />
class CastTest {<br />
    const string COL = "test";<br />
    static void Main() {<br />
        Console.WriteLine("CastTest");<br />
        ArrayList list = new ArrayList();<br />
        string str = "Hello world";<br />
        list.Add(str);        <br />
        Console.WriteLine("arrayList created");        <br />
        DataTable table = new DataTable();<br />
        DataRow row = table.NewRow();<br />
        table.Columns.Add(COL);<br />
        table.Rows.Add(row);<br />
        row[COL] = list;                <br />
        Console.WriteLine("table created");        <br />
        object resultObj = table.Rows[0][COL];        <br />
        Console.WriteLine("resultObj: " + resultObj);        <br />
        ArrayList resultList = (ArrayList)resultObj;        <br />
        string resultStr = (string)resultList[0];<br />
        Console.WriteLine(resultStr);<br />
    }<br />
}


The second last WriteLine statement prints: "resultObj: System.Collections.ArrayList". I seem to be retrieving the ArrayList as an object, but I'm unable to cast it. Why?

Thanks in advance.
Cheers,
Michael
GeneralRe: Weird class cast issue Pin
Christian Graus21-Apr-05 17:38
protectorChristian Graus21-Apr-05 17:38 
GeneralRe: Weird class cast issue Pin
serious-sam21-Apr-05 17:51
serious-sam21-Apr-05 17:51 
QuestionHow to Escape the &quot;;&quot; Pin
CSharpBala21-Apr-05 17:14
CSharpBala21-Apr-05 17:14 
AnswerRe: How to Escape the ";" Pin
Ashok Dhamija21-Apr-05 18:05
Ashok Dhamija21-Apr-05 18:05 
AnswerRe: How to Escape the &quot;;&quot; Pin
leppie21-Apr-05 19:42
leppie21-Apr-05 19:42 
Generalconnection.close or .dispose Pin
vcllvc21-Apr-05 16:54
vcllvc21-Apr-05 16:54 
GeneralRe: connection.close or .dispose Pin
Christian Graus21-Apr-05 18:14
protectorChristian Graus21-Apr-05 18:14 
GeneralRe: connection.close or .dispose Pin
Dave Kreskowiak22-Apr-05 1:14
mveDave Kreskowiak22-Apr-05 1:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.