Learning C# (How to create a class)

adamtrask
adamtrask used Ask the Experts™
on
Hello Experts,

I am taking the plunge into C# after acquiring a reasonable knowledge of VB.Net.

I am trying to declare a strongly typed string List in a new class:

Below is how I wrote it in VB.Net and I need some one to translate into C# the initial few lines:


Thanks
Public Class ListsDB
    Private _myCallsList As New List(Of String)
    Private _myTestList As New List(Of String)
    Private _myVisitsList As New List(Of String)
    Public Property MyCallsList() As List(Of String)
        Get
            Return _myCallsList
        End Get
        Set(ByVal value As List(Of String))
            _myCallsList = value
        End Set
    End Property
    Public Property MyTestList() As List(Of String)
        Get
            Return _myTestList
        End Get
        Set(ByVal value As List(Of String))
            _myTestList = value
        End Set
    End Property
    Public Property myVisitsList() As List(Of String)
        Get
            Return _myVisitsList
        End Get
        Set(ByVal value As List(Of String))
            _myVisitsList = value
        End Set
    End Property

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
public class ListsDB
{
    private List<string> _myCallsList = new List<string>();
    private  List<string> _myTestList = new List<string>();
    private  List<string> _myVisitsList = new List<string>();

    public List<string> MyCallsList
    {
        get
        {
            return _myCallsList;
        }
        set
        {
            _myCallsList = value;
        }
    }
}
It's all about syntax at the end of the day. To help you along with understanding some of the C# syntax when you are used to VB.NET use the following conversion tool: http://www.developerfusion.com/tools/convert/vb-to-csharp/
If there is something you don't know how to write in C#, do it in VB.NET and use this tool to convert it understand what the syntactical differences are.

Commented:
Oops, I forgot the rest of the public properties, but I assume you got the idea.

In VB its:
private something as TypeOfSomething
or
private something as New TypeOfSomething()


and in C# it's:
private TypeOfSomething something;
or
private TypeOfSomething something = new TypeOfSomething();

and not forget the ;


For registering events for example:

button1.Click += ....


if you click Tab twice after the += then it also auto completes you with needed text and also creates an empty event handler.

Author

Commented:
Thank you guys

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial