TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rajan Mishra
444
3.3k
54.7k
How to avoid multiple class instances?
Sep 26 2018 2:26 AM
Here I have a sample code in which i am creating the instances of the class and passing more than one time as a parameter. The thing that is bothering me, is why I have to create multiple instances of a single class in all saperate methods is there any possible way to avoid the repetiton of codes.
public void method1()
{
class1 cl= new class1();
c1.filldata();
method2(c1);
}
public string method2(class1 c)
{
class1 c2= new class1();
c2=c;
string data =c2.data;
}
Here in the above code snippet i have instantiated two instance of a class which i want to avoid.
NOTE:
I can not use parametrised class object that is passed to method2. This is because i need a new object.
Reply
Answers (
1
)
Register user control in share point master page
minimize the size between the rows of a table in crystal rep