473,725 Members | 2,242 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Fic heiro f)
{
_listaF.Add(f);
}
public ArrayList getTodosFicheir os()
{
return _listaF;
}
}

class misc_f
{
public static ListaFicheiro Abrir(string strMyDirectoria )
{
DirectoryInfo di = new DirectoryInfo(s trMyDirectoria) ;
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 2100
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.co m

"Pedro" <Pe***@discussi ons.microsoft.c om> wrote in message
news:05******** *************** ***********@mic rosoft.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(Fic heiro f)
{
_listaF.Add(f);
}
public ArrayList getTodosFicheir os()
{
return _listaF;
}
}

class misc_f
{
public static ListaFicheiro Abrir(string strMyDirectoria )
{
DirectoryInfo di = new DirectoryInfo(s trMyDirectoria) ;
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***@discussi ons.microsoft.c om> 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(s trMyDirectoria) ;
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.co m>
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(str ing 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(s tring strDirectoria)
{
m_directoria = strDirectoria;
}
public string getDirectoria()
{
return m_directoria;
}
public void setDestino(stri ng strDestino)
{
m_destino = strDestino;
}
public string getDestino()
{
return m_destino;
}
public void setFicheiro(Fil eInfo 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***@discussi ons.microsoft.c om> 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(s trMyDirectoria) ;
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.co m>
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***@discussi ons.microsoft.c om> 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(s trMyDirectoria) ;
FileInfo[] fi = di.GetFiles();
ListaFicheiro lif = new ListaFicheiro() ;
foreach (FileInfo fiTemp in fi)
{
Ficherio fich = new Ficherio();
fich.setFicheir o(fich);
lfi.addFicheiro (fich);
}
return lfi;
}
}

--
Jon Skeet - <sk***@pobox.co m>
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
4147
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
8
1955
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 creates output like this (some excerpts): #define DATABITS_8 ((WORD)0x0008) #define KEY_WRITE ((STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY) & (~SYNCHRONIZE)) #define MS_NBF "MNBF" #define PSN_FIRST (0U-200U)
8
3650
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
5749
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
9328
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 = managedInt; Also it would be nice to know how to do this: System::UInt64 managedInt;
7
30784
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 along. It says it's an invalid cast. However, if I use the Convert.ToInt32() method (for example) things will work. At least, that's how it appears to me. Could someone explain when to use old-style parenthesized casts vs. the Convert() methods?
8
8386
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 and display it. I tried with TypeConverter.GetConverter().ConvertToString() functionality. and String.Format() functionality. But i get the value as "System.UInt16" as string.
2
7226
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): m_strCardName(strCardName),
7
16700
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 returned from the source. My first attempt was as follows; (please ignore that error handling is not present in this example) public T GetValue<T(string objName) { T results;
9
17557
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() == "3"; Convert<HelloWorld>::Get() == "HelloWorld"; The reason I need this is that in our design every class of a certain
0
8749
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9103
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8084
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6700
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6009
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4508
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4779
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3217
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.