A non-invoking element cannot be used as a method

I am trying to rewrite a VB function in C #, but I am getting the following error:

Error 1 The non-invoking element "System.DateTime.Today" cannot be used as a method. C: \ Documents and Settings \ daultrd \ Local Settings \ Temp \ SSIS \ ST_ceaa126ff88343ccbfdc6dd27d8de1a7 \ ScriptMain.cs 56 67 ST_ceaa126ff88343ccbfdc6dd27d8de1a7

And offensive line:

strTomorrow = Convert.ToString(String.Format(DateTime.Today().AddDays(+1), "yyyyMMdd")); 

How can i fix this? Thank you, guys; you are very fast! And you all said the same thing. So I removed the bracket, but now I get another error:

Error 1 The best overloaded method match for 'string.Format (System.IFormatProvider, string, params object [])' has some invalid arguments C: \ Documents and Settings \ daultrd \ Local Settings \ Temp \ SSIS \ 2e23c9f006d64c249adb3d3a2e597591 \ ScriptMain.cs 56 44 st_ceaa126ff88343ccbfdc6dd27d8de1a7

And here is this line of code:

 strTomorrow = Convert.ToString(String.Format(DateTime.Today.AddDays(+1), "yyyyMMdd")); //Strings.Format(DateAndTime.Today().AddDays(+1), "yyyyMMdd")); 
+4
source share
4 answers
 strTomorrow = DateTime.Today.AddDays(1).ToString("yyyyMMdd"); 
  • String.Format always returns a string, there is no need to convert the result to a string
  • String.Format does not accept DateTime as its first argument. The easiest way to convert a DateTime to a string in a specific format is to call DateTime.ToString and pass the format as an argument
+8
source

Today is a property, so you should not add parentheses. You also have string.Format arguments.

 strTomorrow = String.Format("{0:yyyyMMdd}", DateTime.Today.AddDays(+1)); 
+1
source

Change DateTime.Today().AddDays(1) to DateTime.Today.AddDays(1)

Today it is a property, not a method.

0
source

DateTime.Today is a property, not a method. Remove the brackets.

0
source

Source: https://habr.com/ru/post/1347316/


All Articles