|
Here are two ways you can do that:
File.WriteAllText(@"C:\mytextfile.txt", string.Empty);
((new FileInfo(@"C:\mytextfile.txt")).Open(FileMode.Truncate)).Close();
If you meant you want to delete a file, you can do this:
File.Delete(@"C:\mytextfile.txt");
|
|
|
|
|
See here[^]. This link give you an idea on how to do basic IO operations on a text file. You can open a file and clear its contents using these IO functions.Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
Hi,
I have to different type of lists.
List<firstclass>
List<secondclass>
i'm trying to add to the List<SecondClass> the List<FirstClass>
List<SecondClass> secondClass = new List<SecondClass>();<br />
<br />
foreach (FirstClass item in query.ToList())<br />
{<br />
<br />
secondClass.Add(item);<br />
}
What i need to do to be able to add FirstClass items to SecondClass list?
Can someone please help me?
|
|
|
|
|
Make sure FirstClass derives from SecondClass.
|
|
|
|
|
List<T> is meant to contain only items of type T or a derivative of T.
Just like an array of int is meant to contain only int values.
That is the whole purpose of generics.
If you need a list to hold all kinds of objects, you have to find a common type T.
In the extreme, you'd have List<T> which is very much like the old ArrayList. But then you loose all the advantages of generics.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
I understand.
Can i convert it to SecondClass [] instead of List<secondclass>?
|
|
|
|
|
what are you rambling about?
- changing a List<SecondClass> to a SecondClass[] array will not change the ability to "add" items of another type.
- turning a List into an array is what List<T>.ToArray() does.
I strongly recommend you read up on arrays and generic collections. Buy and study a book on C#. And use the MSDN documentation. And learn to use Google.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
See? It *is* worse..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
That has the same exact issue as List<SecondClass>. All generic collections would have this issue.
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:08am.
|
|
|
|
|
Not really. If you just create a List<object>, that will work too... or if both classes derive from some other common type, that'd work too.
|
|
|
|
|
Create a base class (let's call it "MyBaseClass ") from which to derive FirstClass and SecondClass .
At that point, you can create
List<MyBaseClass> myList = new List<MyBaseClass>();
and then you can add any object derived from MyBaseClass to myList .
If you want to know how/why this works, use google..45 ACP - because shooting twice is just silly----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
modified on Saturday, February 27, 2010 2:21 PM
|
|
|
|
|
John, the HTML monster may have eaten part of your message. And a little () would be welcome too.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Ooops - fixed. .45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi My friends,
When you have a tabcontrol with some tabpages, how can browse tabpages automatically.
For example you located in tabpage3 and you need to go to tabpage4 after clicking a button.Best Regards,
Reza Shojaee
|
|
|
|
|
Hi,
use TabControl.SelectedTab or TabControl.SelectedIndex . It is all documented.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Luc Pattyn wrote: It is all documented.
Harumph... That's the same as saying "use google". .45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: That's the same as saying "use google".
Not really, there is no problem in locating the information. The only problem seems to be lack of willingness to read it.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Luc Pattyn wrote: The only problem seems to be lack of willingness to read it.
I don't think that's the only problem... .45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Cheer up, John; it can't be all that bad.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
You're right... It's worse. .45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I want to convert a .doc file to .txt file, can some body help me out. I tried with Stream Reader but iam getting Some Junk code in additon to Actual code....
|
|
|
|
|
|
... or read the documentation[^] and implement it yourself.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Hi everybody
What is the best method for storing passwords in SQL database through C# ?Best Regards,
Reza Shojaee
|
|
|
|