Tech Off Post

Single Post Permalink

View Thread: C# Sting converstion
  • W3bbo

    peoples said:
    W3bbo said:
    *snip*

    I'm no good at this, this is my code.

    there is an error on the line, [string mydate..... ]and the next one ????????

     

    int thedate = this.dateTimePicker1.Value.Day & this.dateTimePicker1.Value.Month & this.dateTimePicker1.Value.Year;

    string mydate = thedate.ToString;

    this.richTextBox1.SaveFile(mydate);

    Your code won't work. In C# the '&' operator is bitwise AND, so your code is doing the bitwise AND of the integer representations of day, month, and year, which is meaningless.

     

    Just do this:

     

    DateTime myDate = myDateTimePicker.Value;

    String dateAsAString = myDate.ToString();