|
Straight from a google search of "constructor"
In object-oriented programming, a constructor (sometimes shortened to ctor) in a class is a special block of statements called when an object is created, either when it is declared (statically constructed on the stack, possible in C++ but not in Java and other object-oriented languages) or dynamically constructed on the heap through the keyword "new".
A constructor is similar to an instance method, but it differs from a method in that it never has an explicit return type, it's not inherited, and usually has different rules for scope modifiers. Constructors are often distinguished by having the same name as the declaring class. Their responsibility is to initialize the object's data members and to establish the invariant of the class, failing if the invariant isn't valid. A properly written constructor will leave the object in a 'valid' state. Immutable objects must be initialized in a constructor.
Cheers,
|
|
|
|
|
opps ugly message - and I cant edit it :P. just search the definition!!
|
|
|
|
|
Hello All,
Was only hoping for some direction as to a problem I am trying to figure out. I have an array of characters and for this purpose the characters are ABC|C|D|E|F|G|H|I|JKL|...|XYZ|
Here is the issue: I want to find ABC| so that I could read everything after is until I get to JKL|. And then again until I get to XYZ|. Since each char is separately enumerated in the array, is there a way that I could check for the above mentioned string of chars?
I have tried but I keep getting stopped and the one that looked liked it worked... well... was so convoluted, I didn't understand what I did after I wrote it.
Any bone thrown this way would be greatly appreciated.
|
|
|
|
|
If you're doing this in an array of characters and not a string, then I think I would implement a string method to do pretty much the same thing as the string class but on a char array. Then your searching may become somewhat easier. So... IndexOf("ABC") IndexOf("JKL") and grab what you need to based on those indexes.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
wat u trying to achieve here? r u trying read the characters in between the two known string (ABC & JKL)
by the way how come the strings ("ABC" AND "JKL") got stored in char array.
if all of them are stored in char array, you can form these lettere by just appending them (upto 3 char) and compare it with Known string (ABC OR JKL)
|
|
|
|
|
Thank you carbon_golem for your response.
Srini,
srini wrote: wat u trying to achieve here? r u trying read the characters in between the two known string (ABC & JKL)
Yes I am. Let's say I want to write what is between ABC and JKL to a file and then write what's in between JKL and XYZ to the same file.
I can almost see what you are getting at. May I be so bold as to ask if you could expand on it a little bit more.
Also:
srini wrote: by the way how come the strings ("ABC" AND "JKL") got stored in char array.
I was just giving a clear example
|
|
|
|
|
You could use this:
string[] parts = mystring.Split('|');
Then, you could iterate through the string array (parts) to get your values. BTW, you probably don't want to end your string with a "|" character.
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
I am trying to save file (with path) extracted using OpenFileDialog to my app.config settings so the file gets loaded automatically on next execution. Can someone help
|
|
|
|
|
You want to use "settings", not app.config...
In project, right click the project tree item, and select
Add | New Item... | Settings File. <br />
<br />
<div class="ForumSig"> <div style="border:2px solid #FF9900;color:#000000;background-color:#FDF3CF;font-family:Arial;font-size:11px; padding:5px 5px 5px 5px;"><br />
"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<br />-----<br />"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001</div><br />
</div>
|
|
|
|
|
How do I use the settings. I was able to create settings but the data will be different from user to user.
|
|
|
|
|
You can have application-specific settings. You tend to learn things better (and faster) when you work them out on your own instead of asking a question and waiting for an answer.
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
C#/Asp.net SQL question
=======================
Trying to Delete from SQL database through c# code
SqlDataSource s = (SqlDataSource)SqlDataSource1;
s.DeleteCommand = "Delete FROM Messages WHERE MessageID=id";
s.Delete();
('id' was defined like this
int id = Convert.ToInt32(TextBox1.Text.ToString());)
If I say MessageID = 5 instead of MessageID = id it works fine
(s.DeleteCommand = "Delete FROM Messages WHERE MessageID=5";)
Why can't I use variable instead of a value? Can you please help?
|
|
|
|
|
you probably meant to put the value of the variable into the delete command, not the name of the variable:
s.DeleteCommand = string.Format("Delete FROM Messages WHERE MessageID={0}", id);
|
|
|
|
|
Thanks a lot Jimmanuel! I really appreciate it!
First time using this message board and I got the right answer!
|
|
|
|
|
i want to start a program from my application with arguments, that program support file association, so i associate it with a file extension, and its works when i double click on file, but problem is that when i try to run that program with my app with argument then that program just run not open that file thats path is in arguments property and second problem is that its not rasing event when that program closed, here is the code i wrote :
Process tmp_process = new Process();
private void Main_Load(object sender, EventArgs e)
{
tmp_process.Exited += new EventHandler(exited_event);
}
private void button1_Click(object sender, EventArgs e)
{
tmp_process.StartInfo.Arguments = @"C:\new folder\abc.ghj";
tmp_process.StartInfo.FileName = @"C:\program.exe";
tmp_process.Start();
}
void exited_event(object sender, EventArgs e)
{
MessageBox.Show("Closed");
}
any solution ? thanks
Edited :
second problem solved after writing this line :
tmp_process.EnableRaisingEvents = true;
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
modified on Friday, May 30, 2008 12:59 PM
|
|
|
|
|
Put the arguments inside of quotes \"\" since it contains a space in the file path
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
thanks man it worked
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I'm running a process in a thread and want to put the results as they happen in a text box on my form. Is that possible? I cant seem to make it work.
|
|
|
|
|
It's possible, you just have to transfer the results to the UI thread before updating the text box. 2 common ways of doing this:
textBox.Invoke((MethodInvoker)delegate()
{
textBox.Text = "here are the results...";
}); The other common way and recommended way is to use a BackgroundWorker[^] component. It lets you run work on a background thread and call worker.ReportProgress, which fires an event on the proper thread, allowing you to update your UI in there.
Life, family, faith: Give me a visit.
From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of."
Judah Himango
|
|
|
|
|
I don't believe the cast to MethodInvoker is necessary.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
It is because the parameter type is Delegate. The compiler cannot infer which delegate type you mean when passing in an anonymous method; you'll get a "cannot convert anonymous method to type System.Delegate because it is not a delegate type" compiler error.
Life, family, faith: Give me a visit.
From my latest post: "When Constantine severed the Hebrew origins of this faith in Messiah, a new religion was officially created. It is this religion that Orthodox Jews fear their relatives and friends becoming members of."
Judah Himango
|
|
|
|
|
I've being using objectDataSources to populate some data controls lately. My data access objects return collections of objects rather than DataTables or DataSets. The inherent problem with this is you can't sort a collection by any column (e.g. if I had an EmployeeCollection filled with Employee objects I couldn't sort by Employee.LastName in one method and then Employee.Id in another). So I set out to create a sortable list I could inherit from and be able to sort my collections.
What I have is below, but the problem I have is that I'm converting my generic variables to strings so that I can compare them. I suppose this works fine as long as I override ToString() on my objects so that it makes sense, but it seems like a bit of a kludge. Does anyone have any other ideas that might work?
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
namespace IssueTracker.Business.Collections
{
public class SortableList<T> : List<T>
{
public void SortBy(string sortExpression, SortDirection sortDirection)
{
Sort(delegate(T t1, T t2) { return Compare(t1, t2, sortExpression, sortDirection); });
}
private static int Compare(T t1, T t2, string propertyName, SortDirection sortDirection)
{
object t1Value = t1.GetType().GetProperty(propertyName).GetValue(t1, null);
object t2Value = t2.GetType().GetProperty(propertyName).GetValue(t2, null);
StringComparer comparer = StringComparer.CurrentCulture;
int result = comparer.Compare(t1Value.ToString(), t2Value.ToString());
if (sortDirection == SortDirection.Descending)
result = result*-1;
return result;
}
}
}
|
|
|
|
|
I'm not sure what you are trying to do but List<> is already sortable
public class Employee
{
public string FName;
public string LName;
public Employee(string fname, string lname) { FName = fname; LName = lname; }
public static int CompareFirstName(Employee e1, Employee e2)
{ return e1.FName.CompareTo(e2.FName); }
public static int CompareLastName(Employee e1, Employee e2)
{ return e1.LName.CompareTo(e2.LName); }
}
List<Employee> list = new List<Employee>();
list.Add(new Employee("Joe", "Smakatelly"));
list.Add(new Employee("Sue", "Rummy"));
list.Sort(Employee.CompareFirstName);
Console.WriteLine("First Name");
foreach (Employee e in list)
Console.WriteLine("{0} {1}", e.FName, e.LName);
list.Sort(Employee.CompareLastName);
foreach (Employee e in list)
Console.WriteLine("{0} {1}", e.FName, e.LName);
led mike
|
|
|
|
|
Hello my name is Henry Javier.
I need implement an application to take the total control of PC, this is similar of a cyber control application....
please helme... this is for my university...
I sorry my english is very bad....
Hola a todos mi nombre es Henry Javier y necesito crear una aplicacion en C# la cual sea capaz de tomar el control total de una PC algo similar a un cyber cafe...
me pueden ayudar....
por favor
|
|
|
|
|
hendryck wrote: I sorry my english is very bad....
No importa. Mi espan~ol está mucho mas mal.
But, you know the word "café" also exists in English which results in "cybercafé"
Coffee is the drink. A "café" is a place which sells coffee for consumption on the premisis.
|
|
|
|