473,399 Members | 2,478 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,399 software developers and data experts.

Need help In Object Creation

Hi,
I am developing some windows application tool.Here my doubt is,
I have some 3 classes in the project,
class one
{
Public string getName()
{
return "Nags"
}
}

class three
{
public static object object1;
}
method one:
-----------------
class two
{
[STAThread]
static void Main()
{
one obj=new one()
MessageBox.Show(obj.getName);
}
}
methos 2:
---------------
class two
{
[STAThread]
static void Main()
{
two obj= (two)three.object1;
MessageBox.Show(obj.getName);
}
}
In the above two methods which one is better?and tel me why?
if second one is better means what about the cpu usage(when i go for more objects)

Regards
Nags
Oct 10 '07 #1
4 1007
Plater
7,872 Expert 4TB
I don't believe that code would work, regardless of which one is better.
Oct 10 '07 #2
ok here is the complete tested code,

private void Form1_Load(object sender, EventArgs e)
{
--------------------------------------------------------------------
method1:
Class2 class2 = new Class2();

MessageBox.Show(class2.GetName);
---------------------------------------------------------------------------
method2:
Class3.object1 = new Class2();
Class2 newobj = (Class2)Class3.object1;
MessageBox.Show(newobj.GetName);

}
class2:
----------
class Class2
{
public string GetName
{
get
{
return "nags";
}
}
}
class3:
-----------
class Class3
{
public static object object1;
}

This is working fine.here i have given simple example ithink you will understand this time better.
Regards,
Nags.
Oct 10 '07 #3
Plater
7,872 Expert 4TB
Seems to me that method 2 is worse since it's doing all that extra work of casting things as objects.
Oct 10 '07 #4
Thanks for your reply.Ok if i am going for the Class4
Class4
{
//want to access the Class2 data
Step1
-------
Create object using new Class2();
Step2:
---------
Using the above method2
}

Now what will the issue?which one better method now?which one affect my performence?and why:
Regards,
Nags.
Oct 11 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
7
by: Richard | last post by:
Hi all, I am looking for some help on understanding the overhead associated with object creation in Java. I am writing an application where I have written a class to encapsulate some text...
11
by: cfchou | last post by:
hi, all, i'm reading ch.20 -smart pointers- of . and i'm tring the trule.hpp test. but there's something different than i expect, and i found that's about temp object. so i simplified the...
54
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
8
by: Anthony Munter | last post by:
I have a web application with impersonate=”true” in Web.config and on my own logon page I allow the user to either - specify a userid/password for the app to impersonate when calling legacy...
3
by: Nick Dreyer | last post by:
I was quite surprised to notice that Sub New() gets called twice, once at declaration time and once at creation time. I can't figure out why it would be called at declaration if there is no class...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
44
by: petermichaux | last post by:
Hi, I have been using the following line of code to create an object called "Serious" if it doesn't already exist. if (Serious == null) {var Serious = {};} This works in the scripts I use...
1
by: Jeff | last post by:
I have located the following code and trying to change this so I know if the USB device has been inserted or removed. The problem I have is I alwayd get the Console.WriteLine("Usb removed") so I...
0
by: Dhananjay | last post by:
Hi All, I want to develop one application in vb.net for exchange 2000. I tried to add one contact with the code snippet below. The same logic is there for appointment on Microsoft's site. (I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.