471,310 Members | 995 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 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 1101
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

81 posts views Thread by julio | last post: by
32 posts views Thread by Fresh Air Rider | last post: by
3 posts views Thread by needin4mation | last post: by
41 posts views Thread by Rob R. Ainscough | last post: by
1 post views Thread by Bigeloww | last post: by
reply views Thread by rosydwin | last post: by

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.