473,382 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 2083
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
8
by: Thomas Heller | last post by:
I need to convert C preprocessor definitions into python code. The definitions are dumped out of gccxml (see http://www.gccxml.org) , running over the windows header files (for example). This...
8
by: Joe | last post by:
I have a web service which returns many types (classes) to match the return type. I want to cast the return type to the actual class type. For example: namespace Test { class MyClass { ...
1
by: Champika Nirosh | last post by:
Hi, I want to convert ms sql data types to c# system types.. as an example bit >>> System.Boolean money >>> System.decimal etc
3
by: Mike Miller | last post by:
What is the best way to convert a managed unsigned int64 to an unsigned long? Basically I need to do the following: System::UInt64 managedInt = 10; unsigned long unmanagedInt; unmanagedInt =...
7
by: Jim Bancroft | last post by:
Hi everyone, A basic one here, I think. I haven't found the pattern yet, but sometimes when I cast a variable to another type using the "C" style cast operator the compiler refuses to play...
8
by: Prakash | last post by:
Hi Friends, Using Remoting concept, i have send WCHAR values from VC++.net applicaiton to C# applicaiton. In my C# application it is treated as unsigned shot. I need to convert it back to string...
2
by: Vincent RICHOMME | last post by:
Hi, I am developping a software to test smartcard and one of my class is shown below : class SCardCmd { public: SCardCmd(const wxString& strCardName, const wxString& strCmdName):...
7
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be...
9
by: Marco Nef | last post by:
Hi there I'm looking for a template class that converts the template argument to a string, so something like the following should work: Convert<float>::Get() == "float"; Convert<3>::Get() ==...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.