|
No! I was not using word! I was just typing directly into 'THIS' editor of www.codeproject.com!
Kaveh Shahbazian
|
|
|
|
|
hi there:
how can i read araic text from text file????
best regards
|
|
|
|
|
The same way you read English, except right to left
only two letters away from being an asset
|
|
|
|
|
Member 3584153 wrote: how can i read araic text from text file????
TextReader fstream = new StreamReader("myfile.txt");
string s = fstream.ReadToEnd();
led mike
|
|
|
|
|
Or:
string s = File.ReadAllText("myfile.txt");
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
I am a beginner who is learning C# and have come across a problem that, while I have a workaround, would like to find out what I am doing wrong. I have tried searching, but I doubt I am using the correct terminology. Any assistance is very much appreciated!
If I create a class and place an object of that class into an ArrayList, is it possible to access the members of the object of a particular element of the ArrayList without having to first cast it to a new class?
<br />
public class Customer<br />
{<br />
public Name;<br />
}<br />
<br />
ArrayList myArray = new ArrayList();<br />
Customer c = new Customer();<br />
<br />
ArrayList.Add(c);<br />
<br />
ArrayList[0].Name = "Bob Smith";<br />
<br />
Customer temp = new Customer();
temp = ArrayList[0];
<br />
MessageBox.Show(temp.Name);<br />
My understanding of why the first way doesn't work is because an ArrayList could hold different object types. So I need to box/unbox it before I can use it. Is there some other way to go about doing what I am attempting here withouth the boxing/unboxing(I think these are the right terms)? If I am not using the terminology correctly, please let me know as that may be why my searches are comming up with very little information on what I am trying to do.
Thank you for your time and your patience with a beginner!
|
|
|
|
|
hpjchobbes wrote: without having to first cast it to a new class?
.NET 1.X collections require casting. .NET 2.0 introduced Generic Containers (System.Collections.Generic ) that provide typed Collection capabilities.
led mike
|
|
|
|
|
there's always
List< Customer > myArray = new List< Customer > ();
if you aren't tied to using an ArrayList
|
|
|
|
|
hpjchobbes wrote: My understanding of why the first way doesn't work is because an ArrayList could hold different object types. So I need to box/unbox it before I can use it
Sounds about right to me.
You could use a Generic List to achieve what you're trying to do. It is in the System.Collections.Generic namespace, and is similar to an array list, but the items contained in it are strongly typed (so you won't have to do the boxing/unboxing)
You could use it as follows:
<br />
List<Customer> myCustomerList = new List<Customer>();<br />
<br />
Customer customer = new Customer();<br />
<br />
myCustomerList.Add(customer);<br />
myCustomerList[0].Name = "Bob Smith";<br />
----
Edit: Doh! Too slow...
|
|
|
|
|
hpjchobbes wrote: If I create a class and place an object of that class into an ArrayList, is it possible to access the members of the object of a particular element of the ArrayList without having to first cast it to a new class?
You don't cast the object to a new class, you cast the reference of the object to the class. Creating a new class instance serves no purpose at all, that instance would be thrown away when you assign the new reference to the variable.
Customer temp;
temp = (Customer)ArrayList[0];
hpjchobbes wrote: So I need to box/unbox it before I can use it.
Actually, boxing is only used for value types. If you for example store integers in an ArrayList, each integer is boxed inside an object which is stored on the heap. That way the integer becomes a reference type so that the reference can be stored in the ArrayList.
If you are using framework 2, you can use a generic list instead. They are type safe, so there is no need for any casting:
List<Customer> list = new List<Customer>();<br />
list.Add(new Customer());<br />
<br />
list[0].Name = "Eric Gently";<br />
<br />
Customer temp = list[0];
Generic lists also works with value types, so there is no boxing if you store value types in a list.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Thanks for the answers everyone! I am using 2.0 so I looked at the generic List<t> and it seems to do what I need!
Looks like I have yet another topic to add to my list of things to learn: When to use ArrayList or List<t>
Thanks again for the information and assistance!!
|
|
|
|
|
hpjchobbes wrote: Looks like I have yet another topic to add to my list of things to learn: When to use ArrayList or List
There's no need to use ArrayList in .NET 2.0 anymore.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
hpjchobbes wrote: When to use ArrayList
That is very easy: Never.
If you ever need a list of object references, use List<object> instead of ArrayList .
Most of the time when you store objects of different types in a list, they still have a common base type that you can use rather than an object reference, like for example List<Control> for storing references to any type of controls.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Hi I createed a DB under MS SQL 2005, table has 3 columns name, box, PhoneNumber.
In my c# code i want to check if the phone number entered by the user exists under PhoneNumber column of my table.
Thanks in advance.
|
|
|
|
|
So what have you tried that doesn't work?
Most people won't be inclined to give you any help unless they see you've at least tried something yourself.
Posting code that you're having problems with at least shows that you've tried to figure the problem out...
|
|
|
|
|
Create a stored proc something like this and call it from your app.
IF( EXISTS( SELECT * FROM table WHERE PhoneNumber = @PhoneNumber) )
RETURN 1
ELSE
RETURN 0
only two letters away from being an asset
|
|
|
|
|
write a query and check it
|
|
|
|
|
I populated an OleDb DataTable using a multi-table SELECT statement and need to bind some textboxes and comboboxes with the values from either one or the other table contained in the SELECT statement.
However, when I run the program I get the following error:
Child list for SerialNumber cannot be created
What does that error mean?
Thanks.
|
|
|
|
|
polishprogrammer,
Maybe show the SQL you're trying to do and a bit of code...
Regards,
Gareth.
|
|
|
|
|
Thanks. Here's a piece of the SQL SELECT statement:
SELECT ServiceDetails.SerialNumber, ServiceDetails.ManuDate, ServiceDetails.Manufacturer, " +
"ServiceDetails.Customer, ServicDetails.GasType, " +
"SerialNumber.SerialNumber, SerialNumber.Manufacturer, SerialNumber.ManufacturerDate, " +
"SerialNumber.Owner, SerialNumber.GasType, " +
"FROM SerialNumber, ServiceDetails WHERE " +
"SerialNumber.SerialNumber=ServiceDetails.SerialNumber " +
"AND SerialNumber.Manufacturer=ServiceDetails.Manufacturer " +
"AND SerialNumber.ManufacturerDate=ServiceDetails.ManuDate " +
"ORDER BY SerialNumber.SerialNumber"
The databinding that causes the problem involves binding to, say, the Manufacturer field in the SerialNumber table due to the fact that the same field name exists in both tables. I need to qualify the name of the field, but am unsuccessful when trying it in a databinding context, such as:
this.cbManuSer.DataBindings.Add("SelectedValue", dtSer, "SerialNumber.Manufacturer");
If I bind controls to fields in the datatable filled by the SQL SELECT statement given above that have unique names (not belonging to both tables), the binding works fine, but qualifying the name by table doesn't work. I get the Child list for x not created.
There must be a piece I'm missing, but I could not find a discussion of this topic.
|
|
|
|
|
polishprogrammer,
I am not to sure about the error, but i noticed you have an extra comma where there doesn't need to be one.
polishprogrammer wrote:
"SerialNumber.Owner, SerialNumber.GasType, " +
"FROM SerialNumber, ServiceDetails WHERE " +
I am a bit puzzled by your db tables setup though. Why have 3 columns in 2 different tables that are storing the same values?
Regards,
Gareth.
|
|
|
|
|
Thanks. I wound up just changing the names of the fields in one of the data tables and that worked for the data binding issue. Regarding the repetitive fields, well, it takes the 3 fields to uniquely identify a record, but I want to separate the data into two tables because the information in these particular tables aside from the primary key fields is quite different and used in different contexts, for different purposes.
I suppose I could create a lookup table that would link an ID to the three fields and both tables could reference the look up table, but, well, that would require more software revision because the ServiceDetails table is a recent addition to the database in question whereas the SerialNumber table has been used extensively with its current structure for quite some time and I'd have to redo a bit of code to use a modified structure.
|
|
|
|
|
Hi i developed a tool , which allows you to download whole the source code from microsoft at once.
You don't need vs2008 for this, and you can debug the source code without vs2008.
Just grab your copy from Net Mass Downloader.
You can contact me about the tool via my mail address keremskusmezer@gmail.com
Best Regards
Kerem Kusmezer
|
|
|
|
|
There was an excellent article that someone wrote on relation to updating GUI from a seperate thread.
This article related to setting a property called RaiseExceptionOfSomeKind = false.
Very simple yet very effecient.
I am sad to report that I am blanking out compeltely on that article. If someone has the foggiest idea as to what am I talking about please post a link.
This is what happens when you give up drinking..amnesia.
Thanks
|
|
|
|
|
Updating a Gui from a thread other than the one it was created on "often leads to unpredictable results" (MSDN[^]). See here[^] for the proper way to do so.
|
|
|
|