VitzzViperzz
Well-known member
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
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