|
Dear All,
To know the IEnumerable Interface I have done one demo Aplication please let me know whether there is anything wrong in my approach.
class MyFile : FileSystemInfo
{
private FileInfo _strFile;
public MyFile(FileInfo strFile)
{
_strFile = strFile;
}
public override void Delete()
{
_strFile.Delete();
}
public override bool Exists
{
get
{
if (_strFile.Exists)
{
return true;
}
else
{
return false;
}
}
}
public override string Name
{
get { return _strFile.Name;}
}
}
class MyFiles : IEnumerable<MyFile>
{
private string _directoryPath;
private string _fileExtension = "xml";
public MyFiles(string directoryPath)
{
_directoryPath = directoryPath;
}
public string FileExtension
{
get { return _fileExtension; }
set { _fileExtension = value; }
}
#region IEnumerable<MyFile> Members
public IEnumerator<MyFile> GetEnumerator()
{
DirectoryInfo di = new DirectoryInfo(_directoryPath);
FileInfo[] rgFiles = di.GetFiles("*." + _fileExtension);
foreach (FileInfo fi in rgFiles)
{
MyFile ss = new MyFile(fi);
yield return ss;
}
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
DirectoryInfo di = new DirectoryInfo(_directoryPath);
FileInfo[] rgFiles = di.GetFiles("*." + _fileExtension);
foreach (FileInfo fi in rgFiles)
{
MyFile ss = new MyFile(fi);
yield return ss;
}
}
#endregion
}
Here is it's implementation :
static void Main()
{
MyFiles myFS = new MyFiles(@"D:\TestInterface");
foreach(MyFile FS in MyFiles)
{
Console.WriteLine(FS.Name);
Console.ReadLine();
}
}
Here I am trying to Iterate the Files in Certain directory, and it's further implementation would be to Add New Methods to MyFile Class so as to get Certain required Data from the Files.So far it looks good .
I only wanted to know whether my Interface Implementation is Wrong anywhere or require any changes.
Thanks in Advance.
Develop2Program & Program2Develop
|
|
|
|
|
Navneet Hegde wrote: IEnumerator IEnumerable.GetEnumerator()
You dont really need to provide an implementation for that too. Simply return the generic IEnumerable, ie: return GetEnumerator();
Everything else looks fine
|
|
|
|
|
Please provide an example.
Thank You
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
delegate types are sealed, so no.
|
|
|
|
|
You can 'modify' a delegate though. As an example, see how I make Action delegates parallel in my latest article[^].
|
|
|
|
|
I still like that article. I still cannot think of a single instance where I'd use it, but who cares because it's cool.
|
|
|
|
|
Pete O'Hanlon wrote: I still cannot think of a single instance where I'd use it, but who cares because it's cool.
I want to make it even cooler, by taking any delegate type, then generating a DynamicMethod to do the same as I do with the Action delegates.
|
|
|
|
|
Ooohh... Nice. Still coming up blank as to when I would use it. The race is now on to find day to day practical uses.
|
|
|
|
|
Pete O'Hanlon wrote: Still coming up blank as to when I would use it.
With all the news about multicore CPU's, it could be handy anywhere
|
|
|
|
|
All delegates are derived from System.Delegate . But compiler won't allow you to derive from this class, it is done internally. You can always cast any user defined delegates to "System.Delegate" type.
|
|
|
|
|
I am working on CLient/Server Multithreaded messenger built on .Net 2.0 using C# WINFORM. and the classes for communication I am using are TCPListener and TCPClient.
The problem i am facing is that, when i connect two user on remote PCs then if User1 changes the Desktop's theme on its PC while keep the Client-Application open/running and meanwhile User2 send data to User1 then the Client-Application of User1's PC get halted and Server is no more responsive for any activity.
Feedback is higly appreciated....Thnks in advance.
Syed Raheel Noor
Software Developer
|
|
|
|
|
Hi All,
I am not a pro developer, and all of my coding experience has been spent creating small class libraries and functions to be called from applications. In that time I've developed a reasonable grounding in C# coding mechanics and am comfortable with that.
However, I have envisioned a requirement that means I need to code a complete application and user interface, which I've never done before - or seen source code for. In considering the problem I realise that it's something that is easy to screw up, especially if your expectations of the end product are above average.
Given that, i am wondering whether there is a book out there that effectively documents the process of designing and coding a non-trivial application. That way, I would have my way illuminated somewhat as I begin this endeavour.
Does anyone have any suggestions? is my requirement clear? All help and advice will be warmly received.
Regards,
Dave
modified on Monday, July 7, 2008 5:26 AM
|
|
|
|
|
Hmmn. Does the lack of replies mean that this type of resource doesn't exist?
Regards,
Dave
|
|
|
|
|
Hello everyone,
I am using the following commands in Windbg to debug the following simple application, why there is error like, "Note: this object has an invalid CLASS field
Invalid object"?
0:004> ~0e!clrstack -a
OS Thread Id: 0x1194 (0)
Child-SP RetAddr Call Site
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
000000000012efe0 0000064280150182 TestDebugManaged1.Program.foo()
PARAMETERS:
this = 0x0000000002651ac8
LOCALS:
0x000000000012f000 = 0x0000000000000064
0x000000000012f004 = 0x0000000000000001
RSP/REG Object Name
000000000012f020 000006427f67d4a2 TestDebugManaged1.Program.Main(System.String[])
PARAMETERS:
args = 0x0000000002651aa8
LOCALS:
0x000000000012f040 = 0x0000000002651ac8
0:004> !do 0x000000000012f000
<Note: this object has an invalid CLASS field>
Invalid object
0:004> !do 0x000000000012f004
<Note: this object has an invalid CLASS field>
Invalid object
namespace TestDebugManaged1
{
class Program
{
void foo()
{
int a = 100;
while (true)
{
Thread.Sleep(10000);
a++;
}
}
static void Main(string[] args)
{
Program instance = new Program();
instance.foo();
return;
}
}
}
thanks in advance,
George
|
|
|
|
|
Why do you keep asking questions like this ? What bizarre research project are you on that you don't seem to write any *real* code, you do no research of your own, but you ask the most indepth, obscure and ultimately pointless questions here ?
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Sorry Christian.
For this question, actually I have did some research, but you know there are very few documents about WinDbg...
regards,
George
|
|
|
|
|
The best docs I have found is from blog postings on blogs.msdn.com.
|
|
|
|
|
Thanks leppie,
blogs.msdn.com is a very big site.
Any specific links or?
regards,
George
|
|
|
|
|
You get that error if the address you dumped doesn't contain a valid reference type. The local variables in foo are integers, so !DumpVC will probably work.
|
|
|
|
|
Thanks Senthil!
I have tried to use !DumpVC. But it requires the method table ID. I have tried to use clrstack to get the method table, but only address of variable is given. My purpose is to find out the value and type of local variable. Any ideas?
0:004> ~0e!clrstack -a
OS Thread Id: 0x110c (0)
Child-SP RetAddr Call Site
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
000000000012efe0 0000064280150182 TestDebugManaged1.Program.foo()
PARAMETERS:
this = 0x0000000002651ac8
LOCALS:
0x000000000012f000 = 0x000000000000006b
0x000000000012f004 = 0x0000000000000001
RSP/REG Object Name
000000000012f020 000006427f67d4a2 TestDebugManaged1.Program.Main(System.String[])
PARAMETERS:
args = 0x0000000002651aa8
LOCALS:
0x000000000012f040 = 0x0000000002651ac8
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
0:004> !DumpVC
Usage: DumpVC <Method Table> <Value object start addr>
Example: DumpVC 907b50 67903084
regards,
George
|
|
|
|
|
???????????????????????????????? ????????????? ????????????????? ????user and passI want a code login on C#.net pleasssssss
verryyy thank you
|
|
|
|
|
Hello everyone,
When using WinDbg to debug the following simple application, after loading SOS, then I type "!bpmd TestDebugManaged1.exe Program.Foo" to set a breakpoint, there is the error message -- "Found 0 methods...". What is wrong with my input?
namespace TestDebugManaged1
{
class Program
{
void foo()
{
int a = 100;
while (true)
{
Thread.Sleep(10000);
a++;
}
}
static void Main(string[] args)
{
Program instance = new Program();
instance.foo();
return;
}
}
}
thanks in advance,
George
modified on Sunday, July 6, 2008 8:12 AM
|
|
|
|
|
You will get much better answers in the MSDN forum for this type of question
|
|
|
|
|
Hi leppie,
MSDN has tens of sub-forums, and not dedicated debug or WinDbg forum. Which sub-forum in MSDN forum do you mean?
regards,
George
|
|
|
|
|
Just a thought, in case you haven't got an answer. You are aware that Program.Foo from your debugger command and Program.foo which you've declared in the class aren't the same name, as C# is case sensitive.
|
|
|
|