473,763 Members | 4,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create instance of the run-time type of an object

2 New Member
Hi everone

I have myobject of type object and i want to create instance of its real type. All types are standart types. From myobject.getTyp e() and can get its type. But how to create instance ? If anyone know, please write an answer.

Thanks
Sep 28 '08 #1
1 1481
mldisibio
190 Recognized Expert New Member
Per the example at: MSDN - Activator.Creat eInstance(Type)

Expand|Select|Wrap|Line Numbers
  1.       object createdObject = Activator.CreateInstance(typeof(StringBuilder));
  2.       StringBuilder sb = createdObject as StringBuilder;
  3.       if (sb != null)
  4.         sb.AppendLine("I was created dynamically.");
  5.       Console.WriteLine(sb.ToString());
  6.     }
  7.  
Sep 29 '08 #2

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

Similar topics

5
3639
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug puposes only and is not normally visable to the user.) The Thread function is actually in the Form class. Now.. What I am seeing is that when I create an instance of this Class Library's Form, which starts the worker thread, it seems to hose up...
2
1800
by: R. Clausen | last post by:
I am wanting to create a database in UDB (WIN) v8 FP4 using a backup from UDB (WIN) v7.2 FP4. When the restore is complete, I get a DB2 Message 'The command completed successfully.', however, when I try to view a table in the Control Center I get a DB2 Message 'IBM CLI Driver SQL5035N The database requires migration to the current release.'. This migration message occurs when I restore the database into a newly created instance in v8 or...
3
6110
by: Willis | last post by:
Have installed DB2 v8.1 on a SUN 450, with an UltraSPARC-II processor running at 248 MHz, 256 MB RAM, using Solaris 8. Instance creation was smooth, but when trying to create a database I get the error > db2 create db testdb SQL1225N The request failed because an operating system process, thread, or swap space limit was reached. SQLSTATE=57049 /etc/system:
20
8128
by: Hemant Shah | last post by:
Folks, I am using DB2 UDB 8.2 on AIX 5.1. How large of a bufferpool can you create? I tried to create a 4GB bufferpool db2 complained that is cannot allocate enogth memory. I have 16GB on this system. # db2 create bufferpool cfgbuffpool immediate size 1048576 pagesize 4096 SQL20189W The buffer pool operation (CREATE/ALTER) will not take effect until
1
3820
by: ColinWard | last post by:
Hi there. I just tried to create an MDE from an Access XP App but it crashed out and gave me the "Microsoft Access has encountered a problem and needs to close" message. Has anyone seen this? I tried a compact and repair before creating the MDE but no luck. thanks Colin
8
1665
by: Li Pang | last post by:
Hi I want to run my app only one instance, i.e. only one session is allowed to display Thank
4
1647
by: Joe HM | last post by:
Hello - I have a Base Class where I want a New() implemented that can be called from the outside. This New() should create an instance of the appropriate cDerivedX Class ... The following shows a scenario where it was determined that cDerivedA is needed based on a configuration file. Dim lInstance As New cBase()
4
5480
by: VMI | last post by:
For my website, I created CrystalReportTest.rpt (through the designer in VS 2005) and I'd like to be able to display it in viewer.aspx (all in the same project). Viewer.aspx has a Crystal Report viewer but for some reason, I can't create an instance of this report. Therefore, I can't set any of its properties. The only way I was able to run it was through: CrystalReportViewer.ReportSource = Server.MapPath("CrystalReportTest.rpt"); ...
16
3892
by: Mich | last post by:
Hi, i'm building an web application for anonymous users. They can take a look in the website, nothing more. In order to perform other actions, the anonymous user must be logged. So i create an aspx page with the CreateUserWizard control. The user can fill his username, password etc .... My problem is: when an user fills everything and clicks on button "create an account", nothing happens (no error, but no user account created). I...
2
8228
by: Gerobak | last post by:
I install the UDB Ver 8.2 FixPack 9 on HP Proliant Server running RHEL 4 and Java Version is 1.4.2. After install, i try to create new database. i got error "SQL22204N The DB2 Administration Server encountered a non- severe error while executing a request..." and if i try to create again after that error message, i alwasy get error "SQL4414N The DB2 Administration Server is not active...."
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10144
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9937
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7366
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.