?
Solved

convert small class from vb.net to c#

Posted on 2014-07-16
6
Medium Priority
?
476 Views
Last Modified: 2014-07-16
I have isolated the following items but mostly need your help on items 3, 4, and 5:

'<<<<<<<<<<<<<<<<<<<< how to start and end region in C# <<<<<<<<<<<<<<<<<<<<<<<<<   item: 3
'<<<<<<<<<<<<<<<<<<<< how to code get and set in C# <<<<<<<<<<<<<<<<<<<<<<<<<<<<   item: 4
'<<<<<<<<<<<<<<<<<<<< how to code constructor in C# <<<<<<<<<<<<<<<<<<<<<<<<<<<<   item: 5

Question: Could you show me how to convert this class to run in c#?

Thank you.
Imports Microsoft.VisualBasic
''' <summary> 
''' CriteriaCollection class  
''' Author: M. 
''' Date: 3-16-2014
''' </summary>
''' <remarks>Project: xyz</remarks>
Public Class CriteriaCollection

'<<<<<<<<<<<<<<<<<<<< how to start and end region in C# <<<<<<<<<<<<<<<<<<   item: 3
#Region "Class Variables "    
    Private _regionId As long
    Private _metricId As long
    Private _yyyy As String
#End Region

#Region "Properties"

'<<<<<<<<<<<<<<<<<<<< how to code get and set in C# <<<<<<<<<<<<<<<<<<   item: 4
    Public Property RegionId() As long
        Get
            Return _regionId
        End Get
        Set(value As long)
            _regionId = value
        End Set
    End Property

    Public Property MetricId() As long
        Get
            Return _metricId
        End Get
        Set(value As long)
            _metricId = value
        End Set
    End Property

    Public Property YYYY() As String
        Get
            Return _yyyy
        End Get
        Set(value As String)
            _yyyy = value
        End Set
    End Property

#End Region

#Region " Constructors "

    ''' <summary>
    ''' Empty constructor
    ''' </summary>
    ''' <remarks>Properties to be updated after instantiation</remarks>
	
	'<<<<<<<<<<<<<<<<<<<< how to code constructor in C# <<<<<<<<<<<<<<<<<<   item: 5
    Public Sub New()
        '*** empty sub new 
    End Sub

    ''' <summary>
    ''' Constructor to create a new CriteriaObject with all properies assigned
    ''' </summary>
    ''' <param name="regionId">Region ID </param>
    ''' <param name="MetricId">Metric ID</param>
    ''' <param name="email">YYYY string</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal regionId As long, ByVal metricId As long, ByVal yyyy As String)

        _regionId = regionId
        _metricId = metricId
        _yyyy = yyyy

    End Sub

#End Region

End Class

Open in new window

0
Comment
Question by:Mike Eghtebas
  • 3
  • 3
6 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 40200647
There are online code converters that you can use for such tasks.

e.g.


using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
/// <summary> 
/// CriteriaCollection class  
/// Author: M. 
/// Date: 3-16-2014
/// </summary>
/// <remarks>Project: xyz</remarks>
//<<<<<<<<<<<<<<<<<<<<<<<<<<namespace ASPChartComparision required in C#  <<<<<<<<<<<<<<<<<<   item: 2
public class CriteriaCollection
{

	//<<<<<<<<<<<<<<<<<<<< how to start and end region in C# <<<<<<<<<<<<<<<<<<   item: 3
	#region "Class Variables "
	private long _regionId;
	private long _metricId;
		#endregion
	private string _yyyy;

	#region "Properties"

	//<<<<<<<<<<<<<<<<<<<< how to code get and set in C# <<<<<<<<<<<<<<<<<<   item: 4
	public long RegionId {
		get { return _regionId; }
		set { _regionId = value; }
	}

	public long MetricId {
		get { return _metricId; }
		set { _metricId = value; }
	}

	public string YYYY {
		get { return _yyyy; }
		set { _yyyy = value; }
	}

	#endregion

	#region " Constructors "

	/// <summary>
	/// Empty constructor
	/// </summary>
	/// <remarks>Properties to be updated after instantiation</remarks>

//<<<<<<<<<<<<<<<<<<<< how to code constructor in C# <<<<<<<<<<<<<<<<<<   item: 5
	public CriteriaCollection()
	{
		//*** empty sub new 
	}

	/// <summary>
	/// Constructor to create a new CriteriaObject with all properies assigned
	/// </summary>
	/// <param name="regionId">Region ID </param>
	/// <param name="MetricId">Metric ID</param>
	/// <param name="email">YYYY string</param>
	/// <remarks></remarks>

	public CriteriaCollection(long regionId, long metricId, string yyyy)
	{
		_regionId = regionId;
		_metricId = metricId;
		_yyyy = yyyy;

	}

	#endregion

}
//<<<<<<<<<<<<<<<<<<<<<<<<<< I suppose, in C#,  we close namespace by adding } at the end  <<<<<<<<<<<<<<<<<<   item: 6

//=======================================================
//Service provided by Telerik (www.telerik.com)
//Conversion powered by NRefactory.
//Twitter: @telerik
//Facebook: facebook.com/telerik
//=======================================================

Open in new window

0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40200676
Thank you for the link. I will keep it handy. Digging into it I got the following which seems very easily done in C#.

I would appreciate a brief comment and a sanity check on my version of the code below:
// <summary>  
namespace SetCriteriaCollection
{
	public class CriteriaCollection
	{
		public int RegionId {get; set;}
		public int MetricId {get; set;}
		public string YYYY {get; set;}
		public SetCriteriaCollection(int regionId, int metricId, string yyyy)
		{
			RegionId=regionId;
			MetricId=metricId;
			YYYY=yyyy;
		}
	}
}

Open in new window


Mike
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40200680
Other than you changed the data types from long to int and the name of the method from CriteriaCollection to SetCriteriaCollection, it appears to be the same. You're using auto-implemented properties rather than having a backing field, but there's nothing wrong with that.
0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40200695
CriteriaCollection is the class but
SetCriteriaCollection is the name for namespace
I thought namespace ought to be a bit different.

For your information, the subject of my next post will be "how to use CriteriaCollection class to have 4 set criteria collection stored.

I suppose, I better change my class name to RODcriteria and then not to confuse myself when I am working with collection object.

Thanky you for you help.

Mie
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40200703
CriteriaCollection is the class but
SetCriteriaCollection is the name for namespace
Oh, then I read your code wrong. A namespace is nothing more than a container--it's not executable code. So really the name of that "method" is wrong. That is supposed to be the constructor (which in this case takes parameters). Constructors should be named the same as the class they construct, not the namespace.
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40200731
Thanks.
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month16 days, 14 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question