473,241 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

C# OO - 1.1 - going from vb.net to c#

I need a little assistance in developing objects in C#.

Why does my C# obj barf?????

In vb.net I'll create a class obj in vb called ValCriteria. Make it
serializable so make my call as small as possible. Declare my members and
get and set my properties. My constructor is usually left blank unless I'm
initializing a hashtable or something.

Public sub new()

End sub

Then I create a function that returns that obj like so...

Public Shared Function NewValCriteria() As ValCriteria
Return New ValCriteria
End Function
C# is different.
I create my members and properties. Set my constructor(ok by default its
created). Then I try to create my function to create the instance of my obj
and c# continues to barf. Any idea?

Namespace val.business
{
[Serializable ()]
Public class ValCriteria : myBaseClass
{
Public ValCriteria
{
//blank constructor
}

private string _criteriaOne;

public string criteriaOne
{
get
{
return _criteriaOne;
}
set
{
_criteriaOne = value;
}
}

public ValCriteria Load ()
{
return ValCriteria;
}

}
}
Thanks
Feb 1 '06 #1
5 1140
My interpretation of your code is below (I had to get rid of the base type
because it wasn't in the sample):
1: case is important in C#
2: even default ctors have parenthesese
3: shared maps to static; need a "new" operator; also not sure this serves
any purpose when the caller can call new ValCriteria() just as easily

Does that help?

Also:
Make it serializable so make my call as small as possible.


I'm not sure what you mean here, but I don't think it does what you think...

Marc

namespace val.business {
[Serializable()]
public class ValCriteria {
public ValCriteria() {
//blank constructor
}

private string _criteriaOne;

public string criteriaOne {
get {
return _criteriaOne;
}
set {
_criteriaOne = value;
}
}

public static ValCriteria Load() {
return new ValCriteria();
}

}
}
Feb 1 '06 #2
mgonzales3,

Marking a class as serializable doesn't make your calls to methods on
the class "small", it just allows you to take the instance of the class and
then store it in a stream.

Your method should look like this:

public ValCriteria Load ()
{
return new ValCriteria();
}

This way, a new instance of the class is returned.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"mgonzales3" <mg********@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
I need a little assistance in developing objects in C#.

Why does my C# obj barf?????

In vb.net I'll create a class obj in vb called ValCriteria. Make it
serializable so make my call as small as possible. Declare my members and
get and set my properties. My constructor is usually left blank unless
I'm
initializing a hashtable or something.

Public sub new()

End sub

Then I create a function that returns that obj like so...

Public Shared Function NewValCriteria() As ValCriteria
Return New ValCriteria
End Function
C# is different.
I create my members and properties. Set my constructor(ok by default its
created). Then I try to create my function to create the instance of my
obj
and c# continues to barf. Any idea?

Namespace val.business
{
[Serializable ()]
Public class ValCriteria : myBaseClass
{
Public ValCriteria
{
//blank constructor
}

private string _criteriaOne;

public string criteriaOne
{
get
{
return _criteriaOne;
}
set
{
_criteriaOne = value;
}
}

public ValCriteria Load ()
{
return ValCriteria;
}

}
}
Thanks

Feb 1 '06 #3
again. the team from redmond and elsewhere are found helping us smaller folks.

it works.

thanks
Feb 1 '06 #4
I'm not from Redmond =)

I would fall in the "elsewhere" category. I don't work for Microsoft...
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"mgonzales3" <mg********@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
again. the team from redmond and elsewhere are found helping us smaller
folks.

it works.

thanks

Feb 1 '06 #5

"mgonzales3" <mg********@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
I need a little assistance in developing objects in C#.

Why does my C# obj barf?????


While others have tried to give you some rational replies for you problem, I
would like to present a more esoteric explaination.

As Visual Studio has an inbuilt AI that 'feels' you are a VBer, all your
classes will implement IBarfable and most of your code gets wrapped with a
secret keyword:

barf(MyClass o = new MyClass()) { //code; }

... which is suggar, like the using statement, that translates into

MyClass o = new MyClass();
((IBarfable)o).Barf();

While I provide no proof for this; I'm pretty sure that this is what's
actually going on..
Perhaps Nicholas or Jon knows more... =)

Happy Coding
- Michael S
Feb 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

81
by: julio | last post by:
Sorry but there is no another way, c# .net and mono are going to rip python, not because python is a bad lenguage, but because is to darn old and it refuses to innovate things, to fix wrong things,...
32
by: Fresh Air Rider | last post by:
Hi I understand that ASP.net 2.0 (Whidbey) is going to reduce coding by 70%. Surely this is going to de-skill or dumb down the developer's task and open up the task of web development to less...
4
by: nospam | last post by:
HtmlSelect has a method called OnServerChange that supposed to detect whether the control (select) has changed on a postback. This is not all that useful. It should be like the asp.net...
3
by: Rod | last post by:
In Dino Esposito's book, "Programming Microsoft ASP.NET", there is a chapter titled, "ASP.NET State Management". There is a section in there discussing session state sometimes going away. He...
3
by: needin4mation | last post by:
Is the framework going to change so that on sorting it will have some way of letting you sort two ways, asc or desc? Is the framework's paging going to change so that it does not bring back the...
41
by: Rob R. Ainscough | last post by:
I keep hearing persistant rumors (along with my own experience) that .NET is going to be abandon by Microsoft due to performance & security issues? I realize no one from Microsoft is likely to...
12
by: Jeff | last post by:
Looking for your highly subjective opinions (from those of you who have been working extensively with VS 2005). I have a client that needs/wants a complete rewrite of an existing application. I...
0
by: MikeY | last post by:
Hi everyone, I posted a question very early today, but maybe I wasn't articulate enough. Hopefully this will illicit a response I've created a windows form and a User Control. This is a...
1
by: Bigeloww | last post by:
Dollar is going to rise! Good news for US http://my.usatodays.us/money/myusatoday.html ---------------------------------- http://community.ihostasp.net ASP.NET Developer Community
22
by: Rickster66 | last post by:
As Instructed this is a new thread regarding my original post: "Select Only 10 Columns Going Back" I'm sorry for the late response. I've been gathering up information and carefully with as much...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.