471,306 Members | 1,249 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

Convert types to types

Hi all

I have this code and give me a eeror in converter type , some one can help me:
class ListaFicheiro
{
ArrayList _listaF = new ArrayList();

public void addFicheiro(Ficheiro f)
{
_listaF.Add(f);
}
public ArrayList getTodosFicheiros()
{
return _listaF;
}
}

class misc_f
{
public static ListaFicheiro Abrir(string strMyDirectoria)
{
DirectoryInfo di = new DirectoryInfo(strMyDirectoria);
FileInfo[] fi = di.GetFiles();
foreach (FileInfo fiTemp in fi)
{
ListaFicheiro lfi = fiTemp; // My error is in this line!!!
}
return lfi;
}
}
The idea is to charge an arraylist with files in a directory.

--
Thanks ,

Pedro
Jan 12 '06 #1
4 1998
Pedro,

Well, you are trying to cast a FileInfo instance to your ListaFicherio
instance when there is no connection between the two.

What are you trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Pedro" <Pe***@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...
Hi all

I have this code and give me a eeror in converter type , some one can help
me:
class ListaFicheiro
{
ArrayList _listaF = new ArrayList();

public void addFicheiro(Ficheiro f)
{
_listaF.Add(f);
}
public ArrayList getTodosFicheiros()
{
return _listaF;
}
}

class misc_f
{
public static ListaFicheiro Abrir(string strMyDirectoria)
{
DirectoryInfo di = new DirectoryInfo(strMyDirectoria);
FileInfo[] fi = di.GetFiles();
foreach (FileInfo fiTemp in fi)
{
ListaFicheiro lfi = fiTemp; // My error is in this line!!!
}
return lfi;
}
}
The idea is to charge an arraylist with files in a directory.

--
Thanks ,

Pedro

Jan 12 '06 #2
Pedro <Pe***@discussions.microsoft.com> wrote:
I have this code and give me a eeror in converter type , some one can help me:
<snip>
class misc_f
{
public static ListaFicheiro Abrir(string strMyDirectoria)
{
DirectoryInfo di = new DirectoryInfo(strMyDirectoria);
FileInfo[] fi = di.GetFiles();
foreach (FileInfo fiTemp in fi)
{
ListaFicheiro lfi = fiTemp; // My error is in this line!!!
}
return lfi;
}
}
The idea is to charge an arraylist with files in a directory.


Well yes - you've got a FileInfo, and you're trying to treat it as a
ListaFicheiro, which it isn't. What are you expecting this to do?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 12 '06 #3
I have one other class that is :

public class Ficheiro
{
private string m_nome;
private string m_extensao;
private long m_totfich;
private string m_directoria;
private string m_destino;
private FileInfo m_file;

public void setNome(string nome)
{
m_nome = nome;
}
public string getNome()
{
return m_nome;
}
public void setExtensao(string extensao)
{
m_nome = extensao;
}
public string getExtensao()
{
return m_nome;
}
public void setTotFich(long totfi)
{
m_totfich = totfi;
}
public long getTotFich()
{
return m_totfich;
}
public void setDirectoria(string strDirectoria)
{
m_directoria = strDirectoria;
}
public string getDirectoria()
{
return m_directoria;
}
public void setDestino(string strDestino)
{
m_destino = strDestino;
}
public string getDestino()
{
return m_destino;
}
public void setFicheiro(FileInfo fi)
{
m_file = fi;
}
public FileInfo getFicheiro()
{
return m_file;
}
}

Is to put in one arraylist all files in a directory.

--
Thanks ,

Pedro
"Jon Skeet [C# MVP]" wrote:
Pedro <Pe***@discussions.microsoft.com> wrote:
I have this code and give me a eeror in converter type , some one can help me:


<snip>
class misc_f
{
public static ListaFicheiro Abrir(string strMyDirectoria)
{
DirectoryInfo di = new DirectoryInfo(strMyDirectoria);
FileInfo[] fi = di.GetFiles();
foreach (FileInfo fiTemp in fi)
{
ListaFicheiro lfi = fiTemp; // My error is in this line!!!
}
return lfi;
}
}
The idea is to charge an arraylist with files in a directory.


Well yes - you've got a FileInfo, and you're trying to treat it as a
ListaFicheiro, which it isn't. What are you expecting this to do?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 12 '06 #4
Pedro <Pe***@discussions.microsoft.com> wrote:
I have one other class that is :
<snip>
Is to put in one arraylist all files in a directory.


I still don't see how you expect to convert from FileInfo to
ListaFicheiro though. I suspect you *may* want this:

class misc_f
{
public static ListaFicheiro Abrir(string strMyDirectoria)
{
DirectoryInfo di = new DirectoryInfo(strMyDirectoria);
FileInfo[] fi = di.GetFiles();
ListaFicheiro lif = new ListaFicheiro();
foreach (FileInfo fiTemp in fi)
{
Ficherio fich = new Ficherio();
fich.setFicheiro(fich);
lfi.addFicheiro(fich);
}
return lfi;
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 12 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Thomas Heller | last post: by
8 posts views Thread by Joe | last post: by
3 posts views Thread by Mike Miller | last post: by
7 posts views Thread by Jim Bancroft | last post: by
8 posts views Thread by Prakash | last post: by
2 posts views Thread by Vincent RICHOMME | last post: by
9 posts views Thread by Marco Nef | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.