Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I try to store the current date in the variable and compare it using if condition and for loop.
While I try to store the date in the variable, it shows the error a get or set accessor expected.
I dont know how to solve it

What I have tried:

C#
DateTime date = DateTime.Now;
int i;
for(i=0;i<1;i++)
{
    
}
}

Here in the data type it shows the error
Posted
Updated 8-Aug-19 1:14am
v2
Comments
F-ES Sitecore 8-Aug-19 6:44am    
Post the full code, I don't see how the code you have posted can cause that error.
Richard MacCutchan 8-Aug-19 6:57am    
Lots of code missing, and why are you writing a loop that has only one iteration?
Member 14554066 8-Aug-19 7:02am    
I didnot complete the code, after declare the variable for store the date it shows the error. Thats y I stop the coding
CPallini 8-Aug-19 7:24am    
Anyway you should show us your attempt, in order to make us understand what could be the problem.
Richard MacCutchan 8-Aug-19 7:59am    
If that is all the code you have then you need to go back to your notes, and study how to write a proper class and methods.

Try deleting the last brace, you have one too many !
 
Share this answer
 
Comments
Member 14554066 8-Aug-19 7:03am    
It is for method closing brace
MadMyche 8-Aug-19 7:13am    
Then you may want to think about posting the ENTIRE method as opposed to just a line of code
The error is a little ambiguous, but it is pretty accurate:
"A get or set accessor expected."
Means that you have tried to use a method name instead of a property, and it expects you to supply "()" to indicate it's a method.

That means that the code you showed us isn't the code you are compiling: Now is the only property or method in there and it definitely is a property, not a method.

So look at your actual code and check the line the error is showing up on - the red line should help you with exactly what part of the has the problem, and it should be pretty obvious (or goto the definition if you still aren't sure).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900