Jump to content

C# Example

Archangel1994
Go to solution Solved by Archangel1994,

Never mind, I just found out

Hello good folk of the LTT community,

 

I come before you with a quick question. Can someone explain, line by line, what this next segment of C# coding means?

 

public bool IsPrimeNumber(int n)

{

    for (int i = 2; i < n;i++)

        if (n % i == 0)

            return false;

    return true

}

 

So far I know:

 

1. it's a public (always accessible) boolean method called IsPrimeNumber, I don't know what the parameter int n means.

2. int i is 2, the condition is i must be lower than n and if the condition is met then after the instructions i must be increased by 1

3. if n modulus division i (don't know the exact naming in english) is 0 then return false

4. otherwise return true

 

Could someone correct where I am wrong and fill in the missing information and explain how this will show what numbers are prime numbers?

RIG: I7-4790k @ 4.5GHz | MSI Z97S SLI Plus | 12GB Geil Dragon RAM 1333MHz | Gigabyte G1 Gaming GTX 970 (1550MHz core/7800MHz memory) @ +18mV(Maxed out at 1650/7800 so far) | Corsair RM750 | Samsung 840 EVO 120GB, 1TB Seagate Barracuda | Fractal Design Arc Midi R2 (Closed) | Sound Blaster Z                                                                                                                        Getting: Noctua NH-D15 | Possible 250GB Samsung 850 Evo                                                                                        Need a console killer that actually shits on every console? Here you go (No MIR/Promo)

This is why you should not get an FX CPU for ANY scenario other than rendering on a budget http://linustechtips.com/main/topic/286142-fx-8350-r9-290-psu-requirements/?p=3892901 http://linustechtips.com/main/topic/266481-an-issue-with-people-bashing-the-fx-cpus/?p=3620861

Link to comment
Share on other sites

Link to post
Share on other sites

Never mind, I just found out

RIG: I7-4790k @ 4.5GHz | MSI Z97S SLI Plus | 12GB Geil Dragon RAM 1333MHz | Gigabyte G1 Gaming GTX 970 (1550MHz core/7800MHz memory) @ +18mV(Maxed out at 1650/7800 so far) | Corsair RM750 | Samsung 840 EVO 120GB, 1TB Seagate Barracuda | Fractal Design Arc Midi R2 (Closed) | Sound Blaster Z                                                                                                                        Getting: Noctua NH-D15 | Possible 250GB Samsung 850 Evo                                                                                        Need a console killer that actually shits on every console? Here you go (No MIR/Promo)

This is why you should not get an FX CPU for ANY scenario other than rendering on a budget http://linustechtips.com/main/topic/286142-fx-8350-r9-290-psu-requirements/?p=3892901 http://linustechtips.com/main/topic/266481-an-issue-with-people-bashing-the-fx-cpus/?p=3620861

Link to comment
Share on other sites

Link to post
Share on other sites

Never mind, I just found out

It's good to see you figured it out :D Always fun working things out when programming. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×