# Self Study Tips!

Page 1 of 1

## 11 Replies - 2590 Views - Last Post: 12 August 2010 - 12:27 AM

### #1 insanepenguin

Reputation: 7
• Posts: 234
• Joined: 08-July 10

# Self Study Tips!

Posted 14 July 2010 - 07:11 AM

I'm learning C# before starting Uni in September and I find myself trying to memorise programs and repeat them without looking at the code.

But I've noticed I'm just repeating them instead of understanding, for example

```using System;

class RegPay
{
static void Main()
{
decimal LoanAmount; // loan amount
decimal IntRate; // interest rate as a decimal i.e 0.075
decimal PayPerYear; // payments per year
decimal NumYears; // number of years
decimal Payment; // the regular payment
decimal numer, denom; // work variables
double b, e; // base and exponent for call to pow()

LoanAmount = 69950.00m;
IntRate = 0.0399m;
PayPerYear = 12.0m;
NumYears = 30.0m;

numer = IntRate * LoanAmount / PayPerYear;

e = (double)-(NumYears * PayPerYear);
b = (double)(IntRate / PayPerYear) +1;

denom = 1 - (decimal)Math.Pow(b, e);

Payment = numer / denom;

Console.WriteLine("The payment will be: {0:C}", Payment);
}
}
```

Do you think instead of trying to memorise the formulas and programs I should just understand what the program is trying to teach me? My book

Quote

C# 3.0 Beginner's Guide
doesn't say I should try and repeat the examples from memory but I feel unsure whether to move on until I do!

Thanks,

Mike

Is This A Good Question/Topic? 0

## Replies To: Self Study Tips!

### #2 PsychoCoder

Reputation: 1619
• Posts: 19,853
• Joined: 26-July 07

## Re: Self Study Tips!

Posted 14 July 2010 - 07:14 AM

Don't try to memorize sample programs, all that's going to do is allow you to rewrite that particular sample program. Instead spend your time on learning the language, use those sample programs to learn how C# works and what the code is doing.

Doing it that way will give you the skills to write programs from your head, rather than just being able to regurgitate samples you found in a book.

Also, moving this to C# Programmers forum

### #3 Sergio Tapia

• D.I.C Lover

Reputation: 1210
• Posts: 4,124
• Joined: 27-January 10

## Re: Self Study Tips!

Posted 14 July 2010 - 07:18 AM

Wow, I've never heard of someone trying to memorize code. O_O How are you doing that anyway?

Do not memorize code! For example, in the application you posted, try to read along and understand what's happening. "Ah, he created a variable and saved a value to it." "Aha, now he's using it to calculate something by using another variable e; wait, what's e? Oh yeah! That value over there". And so on...

Follow the code along, understand what's happening and try to create something of your own to really understand it.

I'd also recommend buying a rubber duck and explaining your code to the duck like he was a fellow programmer. Imagine he works with you and he wants to understand what your code is doing.

I personally guarantee 100% that you will have a far better understanding of what you're doing if you use the Rubber Duck method.

### #4 insanepenguin

Reputation: 7
• Posts: 234
• Joined: 08-July 10

## Re: Self Study Tips!

Posted 14 July 2010 - 07:23 AM

Thanks guys, I think my time spent studying is going to be much more productive now!

### #5 FlashM

• D.I.C Lover

Reputation: 380
• Posts: 1,195
• Joined: 03-December 09

## Re: Self Study Tips!

Posted 14 July 2010 - 07:26 AM

The point is that you understand the code... A problem can always have many different solutions with same ending result and I don't see a point in memorizing your application's code... But I'm sure you'll get that with lot's of practise... I suggest getting or borrowing some good C# book...

### #6 Momerath

• D.I.C Lover

Reputation: 809
• Posts: 1,947
• Joined: 04-October 09

## Re: Self Study Tips!

Posted 14 July 2010 - 07:40 AM

```using System;

class RegPay {
static void Main() {
decimal LoanAmount; // loan amount
decimal IntRate; // interest rate as a decimal i.e 0.075
decimal PayPerYear; // payments per year
decimal NumYears; // number of years
decimal Payment; // the regular payment
decimal numer, denom; // work variables
double b, e; // base and exponent for call to pow()
```

Why are some of these decimal and other double? What do decimal and double mean?

```        LoanAmount = 69950.00m;
IntRate = 0.0399m;
PayPerYear = 12.0m;
NumYears = 30.0m;
```

What is this code doing? Why did they put m at the end of the numbers?

```        numer = IntRate * LoanAmount / PayPerYear;
```

What is this code doing? Would it make a difference if I wrote it numer = IntRate / PayPerYear * LoanAmount;? Why or why not?

```        e = (double)-(NumYears * PayPerYear);
b = (double)(IntRate / PayPerYear) +1;
```

Again with the double. What does it mean? What is that minus sign doing in the first line?

```        denom = 1 - (decimal)Math.Pow(b, e);
```

If they had to put a m before for decimals, why don't they have one here after the number 1?

```        Payment = numer / denom;

Console.WriteLine("The payment will be: {0:C}", Payment);
}
}
```

What is going on in the last line? What does {0:C} mean?

### #7 taylorc8

• B&

Reputation: 149
• Posts: 1,572
• Joined: 21-July 09

## Re: Self Study Tips!

Posted 14 July 2010 - 08:50 PM

Feel free to play with the examples all you want, even if it's just changing variable names. Make it "your" code.

### #8 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 3793
• Posts: 6,394
• Joined: 08-June 10

## Re: Self Study Tips!

Posted 15 July 2010 - 08:49 AM

One thing I always do when I'm working from an example or a sample, I don't copy and paste. Ever. By typing it myself, I force myself to read every line carefully, especially if I use slightly different variable names. And by reading each line, it helps force me to understand what each line is doing.

### #9 insanepenguin

Reputation: 7
• Posts: 234
• Joined: 08-July 10

## Re: Self Study Tips!

Posted 15 July 2010 - 09:46 AM

I've always done that too Alias, definitely helps!

### #10 FlashM

• D.I.C Lover

Reputation: 380
• Posts: 1,195
• Joined: 03-December 09

## Re: Self Study Tips!

Posted 15 July 2010 - 11:27 AM

Agree on that... You need to force yourself to understand the code... Take a sample and use it in your own way.

### #11 MentalFloss

• Not really an expert anymore...

Reputation: 433
• Posts: 1,157
• Joined: 02-September 09

## Re: Self Study Tips!

Posted 11 August 2010 - 09:25 PM

You're going to learn that in programming, there are certain concepts that need to be understood.

First, they must be understood from a localized level (that is, where the code is written). Next, they need to be understood from an objective level (that is, what is using the code in question).

Let's take the example of a counting application:

First we state exactly what we want:

Quote

Output a new number per line in console starting at 1 and ending on 100.

Next, we write code that does exactly that in our main application:

```public class Program
{
public static void Main()
{
int start = 1;
int stop = 100;

for (int current = start; current <= stop; current++)
{
Console.WriteLine(current);
}

Console.ReadLine(); // Just pauses output so you can see it.
}
}

```

We made use of local variables (start, current, stop) and a for loop. We also made use of two method calls (WriteLine and ReadLine).

So, you can stop there... or we can take it to the next level by creating a method ourselves. Here is the same program but the details have been moved to a new static method.

```public class Program
{
public static void Main()
{
CountAndDisplay();
}

private static void CountAndDisplay()
{
int start = 1;
int stop = 100;

for (int current = start; current <= stop; current++)
{
Console.WriteLine(current);
}
}
}

```

Absolutely nothing really new here except that now we have our own method and our own method call:

```CountAndDisplay();

```

Well, we can stop here OR we can create a class that does the work for us. Let's create a class called "Counter" and a method in there called "Display".

```public class Program
{
public static void Main()
{
Counter myCounter = new Counter();
myCounter.Display();
}
}

public class Counter
{
public void Display()
{
int start = 1;
int stop = 100;

for (int current = start; current <= stop; current++)
{
Console.WriteLine(current);
}
}
}

```

Now we're using objects! See how we create an instance of our Counter class and call its Display method?

See how this is all the same exact work done but said in different ways?

Let's move forward in understanding by creating the start and stop parameters as actual properties of our class:

```public class Program
{
public static void Main()
{
Counter myCounter = new Counter();
myCounter.Display();
}
}

public class Counter
{
public int Start { get; set; }
public int Stop { get; set; }

public Counter()
{
Start = 1;
Stop = 100;
}

public void Display()
{
for (int current = Start; current <= Stop; current++)
{
Console.WriteLine(current);
}
}
}

```

We have something called a constructor now for our class. This is what is going to be essentially our set-up of the object when it is created:

```public Counter()
{
Start = 1;
Stop = 100;
}

```

Let's play around even further (see it's like play-doh!) and add a constructor that accepts an actual start and stop!

```public class Program
{
public static void Main()
{
Counter myCounter = new Counter();
myCounter.Display();

Console.WriteLine(); // Just to get a space between :)/>

Counter myCustomCounter = new Counter(50, 200);
myCustomCounter.Display();

}
}

public class Counter
{
public int Start { get; set; }
public int Stop { get; set; }

public Counter()
{
Start = 1;
Stop = 100;
}

public Counter(int start, int stop)
{
Start = start;
Stop = stop;
}

public void Display()
{
for (int current = Start; current <= Stop; current++)
{
Console.WriteLine(current);
}
}
}

```

And that was all just with a humble beginning as a for loop counter!

You just have to learn to work the dough...

Oh be sure to research why all that stuff I did up there works and how it works. That should be plenty of self-study for you.

### #12 insanepenguin

Reputation: 7
• Posts: 234
• Joined: 08-July 10

## Re: Self Study Tips!

Posted 12 August 2010 - 12:27 AM

Thanks MentalFloss,

Your post should keep me going for a while