Jump to content

C# Code verification

- - - - -

  • Please log in to reply
4 replies to this topic

#1
Thall

Thall

    Newbie

  • Members
  • Pip
  • 7 posts
I'm just learning C# and I know this is really simple code but I'd just like to ask for advice. I wrote a small class that will automatically update the copyright year. Based on what I wrote, does anyone have a different way they would have written it? Or does anything stand out that I should have done differently?

I'm asking because I want to learn to write code using good habits early.

Thanks


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            Copyright getCopywright = new Copyright();

            getCopywright.CopywrightInfo();

        }


        class Copyright

        {


            int startYear = 2010;               //Initialize startYear field

            

            public void CopywrightInfo()

            {

               //Conditional block to determine if the start year and current year are the same

               if (startYear < DateTime.Now.Year)

               {

                   Console.WriteLine("Copywright {0} - {1}", this.startYear, DateTime.Now.Year);

               }

               else

               {

                   Console.WriteLine("Copywright {0} ", this.startYear);

               }

               Console.Read();

            }

        }

    }

}



#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
I think that's solid code. I can't think any other way off the top of my head to check the date, other than using the internet.

The only problem I see is its spelled Copyright not Copywright, other than that, nice code. :)
~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US

Thall said:

I'm asking because I want to learn to write code using good habits early.

If it's habits you're talking about, then I'd say, it's good to have your own style - so long as it works.

#4
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
The only thing I could see is, if startYear never change, maybe making it a constant

#5
Thall

Thall

    Newbie

  • Members
  • Pip
  • 7 posts

CommittedC0der said:

I think that's solid code. I can't think any other way off the top of my head to check the date, other than using the internet.

The only problem I see is its spelled Copyright not Copywright, other than that, nice code. :)
~ Committed.

Thanks. I noticed that after I sent the post. I appreciate your input.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users