473,394 Members | 1,916 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,394 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 1144
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.