|
Hi,
I always use the symbol '@' as a pointer to the first byte of a buffer, but what it means in C# now? Is it a reference or something?
What is the difference between string delimit = @"\"; and string delimit = "\";
Thanks,
Dirso
|
|
|
|
|
Dirso wrote: What is the difference between string delimit = @"\"; and string delimit = "\";
in C# the first compiles, the second does not, due to an invalid escape sequence.
|
|
|
|
|
In C# it means what it's always meant :P
In the case your showing it means 'literal string' i.e.
one which isn't processed and so theres no need to escape anything other than double quotes.
"////machinename//" == @"//machinename/"
It does also have another use which is to allow you to use reserved words as identifiers i.e.
public class @readonly {}
But that is not a good idea reserved words are reserved for a reason
|
|
|
|
|
originSH wrote: "////machinename//" == @"//machinename/"
I don't think so.
|
|
|
|
|
oh nuts ... yeah it should be:
"\\\\machinename\\" == @"\\machinename\"
Good spot
|
|
|
|
|
|
Thank you both! I had needed to use @ in Delphi so much that I completly forgot it's (not too good) use in C. And sorry for the horrible example in my question, of course "\" wouldn't compile, it was just a dummy question
Thank you so much,
Dirso
|
|
|
|
|
|
Ive got a form that the user can enter information on, when clicking the "SAVE" button the general proccess is the following...
private void SaveData()
{
if(dataIsValid())
{
}
}
lets say the form has a TextBox and a ComboBox
the dataIsValid() method will look something like this
private bool dataIsValid()
{
if (textBox1.Text = "")
{
MessageBox.Show("Please Enter A Name");
textBox1.Focus();
return false;
}
else if (comboBox1.SelectedValue == null)
{
MessageBox.Show("Please Select An Age Group");
comboBox1.Focus();
return false;
}
return true;
}
The idea is to one by one check that the fields have data... But now lets add 3 maskedTextBoxes with mask "##:##" for a time span value. Now the data doesn't just have to be there, but valid as well.
the solution i came up with looks dodgy and can be a nightmare to maintain... its as follows
private bool dataIsValid()
{
if (textBox1.Text = "")
{
MessageBox.Show("Please Enter A Name");
textBox1.Focus();
return false;
}
else if (comboBox1.SelectedValue == null)
{
MessageBox.Show("Please Select An Age Group");
comboBox1.Focus();
return false;
}
try
{
TimeSpan.Parse(maskedTextBox1.Text);
try
{
TimeSpan.Parse(maskedTextBox2.Text);
try
{
TimeSpan.Parse(maskedTextBox3.Text);
}
catch
{
MessageBox.Show("Please Enter A Duration");
maskedTextBox3.Focus();
return false;
}
}
catch
{
MessageBox.Show("Please Enter A Duration");
maskedTextBox2.Focus();
return false;
}
}
catch
{
MessageBox.Show("Please Enter A Duration");
maskedTextBox1.Focus();
return false;
}
return true;
}
Does anyone have any better ideas cuz im all out?
Im sure there has to be a better way of doing this...
Thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
u can use the Mask Property that validates for u
and also
use the maskedTextBox1_MaskInputRejected Event that this Param
(object sender, MaskInputRejectedEventArgs e)
and :
e.Position
e.RejectionHint
Have Fun
Never forget it
|
|
|
|
|
Try writing one routine that will validate a control of a given type, then call that routine with each control of that type. It's less code, lower complexity, and only one place to update the validation algorithm if it needs to change.
|
|
|
|
|
I would recommend wiring into all the controls Validating events, then you can just call the forms ValidateChildren method to validate everything. I'd also recommend using an Error Provider, which can display an icon and error tooltip beside each invalid control.
If you'd prefer to keep your current structure for validation and just clean it up a bit, you could use the TimeSpan.TryParse instead of TimeSpan.Parse, like so:
<br />
TimeSpan timeSpan;<br />
if(!TimeSpan.TryParse(maskedTextBox1.Text, out timeSpan)){<br />
}<br />
|
|
|
|
|
thanx for the reply...
i wasnt aware of the TryParse() method... thank you
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
I can see you already got help with that , but just one more thing:
you wrote:
if (textBox1.Text == "")
{
MessageBox.Show("Please Enter A Name");
textBox1.Focus();
return false;
}
and that is not true, it depends on what you expect.
from this code my name can be " " (white space).
besides that, I saw you're using a db, so if you're building you own queries to the database (which in not recommended), my name can be:
"' OR '1'='1", which might get me a log-in to your system, or even something like: "bla'; DROP TABLE Users /*", which of course I need to get the table name right, but usually it is not so hard.
All I'm trying to point out is, be more careful when performing validation.
|
|
|
|
|
Thanks for the reply
The example i gave was just a mock up to demonstrate the BASIC idea of what im doing, the fields get checked for white spaces, special characters etc.
Also the injection wont work because i use stored procedures etc.
Thanx for the heads up anyway
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
hi every body
nice to join you..a friend of me told me about this website.
i have a small project which is to create your own version of arralist in c# but of course without using the arraylist collection ...
i really need some help here.
two classes are reguired: class mylist, class node
class mylist
{
count
node first
node last
//methods:
add(){}//add at last node
remove(){}
removeAt(){}//depends on a specific index of each node
insert(){}//depends on a specific index of each node
sort(){}
reverse(){}//to swap two nodes
removeRange(){}//to delete set of nodes between two indecies
search(){}
getRange(){}//to return how many nodes does the arraylist contain
}
class Node
{
node next;
node previous;
Object value;
index;
}
this is the initial scratch..please i need all help that you can offer me
how can i do this??
while(1)
System.out.println("I love Palestine ");
|
|
|
|
|
This looks like the homework assignment you were given with no work done to me. What do your course notes say ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
i just wanted to have some extra explanation ...thats all
while(1)
System.out.println("I love Palestine ");
|
|
|
|
|
Im also intrested in that topic, so plz help me
thank you
|
|
|
|
|
See here.[^]
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Or if you really need a bit of code to get started:
while (!TurnToBeASplodyDope(lolla2006))
{
try
{
CheatOnMyHomeWork();
}
catch
{
MessageBox.Show("Busted")
}
}
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Now, if you were to publish the implementation of CheatOnMyHomeWork() we might get rid of these
kinds of questions once and for all.
|
|
|
|
|
void CheatOnMyHomeWork()
{
while (!AnswerGivenByASucker && !DueDatePassed)
{
PostPatheticMessagesToProgrammingForums();
}
}
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Why the use of two negation operators?
while (!(AnswerGivenByASucker || DueDatePassed))
{
PostPatheticMessagesToProgrammingForums();
}
Dave
|
|
|
|
|
actually i have already published the implementation of NotYourBusiness()
while(1)
System.out.println("I love Palestine ");
|
|
|
|