Can someone just explain these bits of code?

VitzzViperzz

Well-known member
Joined
Jan 16, 2017
Messages
75
Location
United Kingdom
Programming Experience
1-3
Hello C# forums!!!!

This is my first post and I can't wait to get involved into the incredible world of C# programming. So far I've picked up some terminology and I can't wait to learn more.

But could someone please explain what happens in these pieces of code?


in this first bit of code, I when I run this I just get nothing on the console. And I don't really understand why we have used arrays and lists?

first program:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Arrays_and_Lists
{
class Program
{

public void PrintFirstElement(int[] a)
{


Console.WriteLine("The first element is: {0}.\n", a[0]); // array parameter

int[] myArray = { 1, 2, 3, 4, 5 };
PrintFirstElement(myArray);

}


public void PrintFirstElement(List<int> a)
{
Console.WriteLine("The first list element is {1}.\n", a[0]);

List<int> MyList = new List<int> { 1, 2, 3 };
PrintFirstElement(MyList);
}


public int[] ReturnUserInput()
{
int[] a = new int[3];

for (int i = 0; i < a.Length; i++)
{
Console.WriteLine("Enter an integer: ");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Integer added to array. \n");
}
return a;

int[] myArray2 = ReturnUserInput();

}





static void Main(string[] args)

{

}
}
}




In this bit of code I don't really understand anything! Like nothing! Can someone explain clearly please? Second program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OOP_part_2
{
class Program
{

class Member
{
protected int AnnualFee;
private string Name;
private int MemeberID;
private int memeberSince;

public override string ToString()
{
return "\nName: " + Name + "\nMember ID: " + MemeberID + "\nMember Since: " + memeberSince + "\nTotal Annual Fee: " + AnnualFee;

}

public Member()
{
Console.WriteLine("Parent Constructor with no parameter");
}

public Member(string PName, int PMemberID, int pMemberSince)
{
Console.WriteLine("Parent constructor with 3 parameters");

Name = PName;
MemeberID = PMemberID;
memeberSince = pMemberSince;
}

}
Again, if someone could run over these things, that would be very welcoming to the group!

Cheers
 
Firstly, please don't post code snippets that way. You've actually made the code hard to read and also hard for us to edit in order to make it readable. Post your code snippets wrapped in appropriate formatting tags, i.e.

[xcode=c#]your code here[/xcode]

for syntax highlighting or:

[code]your code here[/code]

to add your own formatting. In both cases, most importantly, indenting will be maintained. There are buttons for both on the advanced editor tool bar.

With regards to the first snippet, the reason you don't see anything happening is that you don't have any code in your Main method. The Main method is the entry point for all applications so if you want anything to happen then you have to initiate it there.

With regards to the second snippet, I find it hard to believe that you don't understand anything but, if you really don't, then you need to do a bit of research for yourself first rather than expect us to explain the absolute basics. If you haven't just randomly plucked that snippet off the web then you must have some idea of what it's supposed to be doing. If you've done any research at all then you must have some idea of how a Console application works. Again, if you've done any research at all then the basics of methods and variables should not be a mystery. If you haven't done any research then you really should do that first. There's a beginners tutorial in my signature below that would be a good place to start. Once you've done some research, if there are some specific things that you don't understand then, by all means, post back about them.
 
Hello,

Thanks for your response.

If you put your glasses on, you should realise that the post that I made was my FIRST post that I have done on this forum. Instead of writing a harsh response, you could write an educational response in order for the new guy to learn the rules of your forum.

I understand you say "It's hard to believe you don't understand anything" but if you understand not everyone is a C# genius like you! Any fool can criticise condemn and complain - Benjamin Franklin. Also if you understood that I have tried all day to find a good explanation and all of them were pants maybe you would take your word back!

I will go through your beginner helps guides to see what I can find!
 
If you put your glasses on, you should realise that the post that I made was my FIRST post that I have done on this forum. Instead of writing a harsh response, you could write an educational response in order for the new guy to learn the rules of your forum.
I already have my glasses on and I already realised that it was your first post. How exactly is my response harsh? Did I call you names? If you put your glasses on you will see that I did tell you what you should do to make a good post.
I understand you say "It's hard to believe you don't understand anything" but if you understand not everyone is a C# genius like you! Any fool can criticise condemn and complain - Benjamin Franklin. Also if you understood that I have tried all day to find a good explanation and all of them were pants maybe you would take your word back!
I'm no C# genius and I don't expect anyone else to be either. What I do expect is for people to do their due diligence. I stand by what I said: I find it hard to believe that you don't understand anything in that code snippet. What I think is actually the case is that you do understand some parts of it and not other parts but you didn't take the time or make the effort to specify which is which. You'd rather that we wasted our time and effort addressing the things that you already know. As I indicated in my previous post, I'm more than happy to help with specific issues but just dumping a chunk of basic code and claiming that you understand nothing is not specific. Either you do understand something or you haven't taken the time to find out about the things that you should be able to understand on your own. I'm not trying to discourage you from programming or from using this or other forums but I am trying to discourage you from taking advantage of strangers on the internet. Do your part and then we'll do ours. Don't expect us to do your part too and we'll get on fine.

Any fool can criticise condemn and complain - Benjamin Franklin. Are you going to be any fool?
 
Back
Top Bottom