|
Okay, so I'm very new to C# (and to programming in general for that matter), but I've come across this idea of boxing and unboxing that seems completely odd. In my understanding, it is a shell game of sorts between a referenced type and a value type. It seems to me that this might save in resources, and that it is similar to casting in C, but it is unclear to me. If anyone could give a reason as to why someone would want to use this technique, I would be very grateful.
"If you really want something in this life, you have to work for it. Now, quiet! They're about to announce the lottery numbers..."
- Homer Simpson
|
|
|
|
|
You can cast anything to the type Object, and back again. This is frequently used when a method takes parameters that can be any data type. For instance the String.Format method:
string s = string.Format("{0}{1}{2}", "The answer is ", 42, ".");
What really happens here is that the method takes an array of objects:
object[] temp = new object[] {(object)"The answer is ", (object)42, (object)"."};<br />
string s = string.Format("{0}{1}{2}", temp);
The strings already are objects, so they can be casted without boxing. For the integer value, though, a new object is created on the heap and the value is copied into the object.
---
b { font-weight: normal; }
|
|
|
|
|
I want to register a .NET assembly as a library, so that any program can import it. As easy as you do with "using System;" how can I do that?
Thank for you help.
|
|
|
|
|
You can add the assembly to the GAC[^] (Global Assembly Cache). That way, the clients of the library can all share the same assembly, instead of each one having a copy in its application directory. Have a look at gacutil[^], which is a utility in the SDK that allows you to add/remove assemblies from the GAC.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
i used the month calendar from the article "ANOTHER MONTH CALENDAR" by Patrick Bohman.
got some questions regarding the control:
1.
the flow of my project is to select a date, give its corresponding datecode(holiday, special holiday or regular day) then select another date.
everytime i choose a another date after the first one, seems i couldn't get the right date selected. i used the DaySelected method. and gets the clicked date by
string[] m_daysSelected = e.Days;
but seems i couldn't get the right days.
how do i do that?
and by the way, i have to remember all the selected dates plus its other corresponding data before i get to save the entire selection of the year.
is that possible?
2.
i have a combo box consisting of different years.
each year has different formatted dates.
how do i copy the formatted dates of the entire year that chosen from the combo box to the recent year?
thanks a lot.
|
|
|
|
|
Then why don't you ask your question in the comments section of the article itself? That would be the right place.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
i want to make my appliction (c#) interface is like windows disktop (icon,start manu)
|
|
|
|
|
|
i want to know about enumrator
omar el halwagy
|
|
|
|
|
1. Spell it correctly: IEnumerator
2. Type this into the top left textbox on CP.
3. Hit enter.
4. Look at the search result list[^].
5. Determine that this article[^] is probably rather good as a starting point.
Robert
|
|
|
|
|
If Robert's response wasn't what you were looking for...
1. Drop the "I" and try the contruct: Enumerator
2. Type this into the top left textbox on CP.
3. Hit enter.
4. Look at the search result.
If neither response helps, try asking a conherent question next time.
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
i'm using sockets, i want to disconnect this socket after connection. but i can't disconnect it. it throws "An invalid argument was supplied"
i write "sck.Shutdown(SocketShutdown.Both)", but it can't work
what must i do plz help!!!
|
|
|
|
|
If you receive a SocketException when calling Socket.Shutdown(), use SocketException.ErrorCode to obtain the specific error code. Once you have this code, refer to WinSock 2 error code documentation[^]for a detailed description of the error.
Best,
Jun
|
|
|
|
|
Hi,
-Is it posible to recieve information about the stacktrace/execution history at runtime??
thx.
|
|
|
|
|
I believe that the easiest way is to just throw an exception and catch it.
string trace = null;<br />
try { throw new Exception(); } catch (Exception ex) { trace = ex.StackTrace; }
---
b { font-weight: normal; }
|
|
|
|
|
|
StackTrace st = new StackTrace();
|
|
|
|
|
Totally off subject, I got a copy of xacc.ide the other day, and it exceptions on load. No meaningful information, just ungracefully croaks.
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
I have been trying to access frames with webBrowser document.
I always get the system telling me I don't have access. I read up on the net and it is a known issue due to security.
Has anyone ever achieved this?
HTMLDocument doc = (HTMLDocument) i_webBrowser.Document;
object aRef = frameNumber;
object anObj = doc.frames.item(ref aRef);
HTMLWindow2 aWindow = (HTMLWindow2) anObj;
HTMLDocument aDoc;
// the line below will cause the security exception
aDoc = (HTMLDocument) aWindow.document;
test
|
|
|
|
|
Hi All!
i am trying to use the ContextMenu control, and i do know how handle a click on it, i mean if you go the Form you can only handle popup event.
i tried to add to one menu item a click hasndler but it does not go in to the function that i created, can some one tell me how can i tell if the MenuItem in the ContextMenu was clicked and how can i handle it.
Thanks
|
|
|
|
|
ytubis wrote: i tried to add to one menu item a click hasndler but it does not go in to the function that i created,
Proper steps are:
1) Click on one menu item
2) Go to the event tab on the property panel
3) Double click on the click event; an event and handler shall be added
4) Find the handler function and fill in the function body with your logic
Best,
Jun
|
|
|
|
|
That is exectlly the problem, i see there only the popup event and not click event or select event and i do not know why??????
|
|
|
|
|
That sounds weired. I use Linux stations at work and only can check it out for you tonight. Hopefully you've found the answer by then.
Best,
Jun
|
|
|
|
|
In VS2003, when you select a menu item and click on the event tab, you should see the following events:
Click
DrawItem
MeasureItem
Popup
Select
Best,
Jun
|
|
|
|
|
Pls can any help me figure out if there is any error in this web sevcice client. I have included Username and Password for testing. When
http://dedicated134.eapps.com/pencomweb2/PENCOM_WebService.asmx is registered
classes exposed are:
PencomServer2.PENCOM_WebService c1 = new PencomServer2.PENCOM_WebService();
PencomServer2.RSANO_Response c2 = new PencomServer2.RSANO_Response();
PencomServer2.EmployeeRecord[] record=new PencomServer2.EmployeeRecord[2];
but of tesing purposes
(string r = c1.TestPenComService();)
can be used.
Sample code is:
required namespace are:
using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Design;// formerly Microsoft.Web.Services3.Policy
using System.Security.Permissions;
using Microsoft.Web.Services3.Security;
using Microsoft.Web.Services3.Security.Tokens;
public void ReadData()
{
//Secure Service
//http://dedicated134.eapps.com/pencomweb2/PENCOM_WebService.asmx
// Create an instance of the Web service proxy
PencomServer2.PENCOM_WebService c1 = new PencomServer2.PENCOM_WebService();
PencomServer2.RSANO_Response c2 = new PencomServer2.RSANO_Response();
PencomServer2.EmployeeRecord[] record=new PencomServer2.EmployeeRecord[2];
// This is the username security token which is used by the service proxy
UsernameToken token = null;
Username = "PENSUREPFA";
Password = "NS946343PE";
byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes(Password);
string passwordEquivalent = Convert.ToBase64String(passwordBytes);
token = new UsernameToken(Username, passwordEquivalent, PasswordOption.SendHashed);
//PolicyEnforcementSecurityTokenCache.GlobalCache.Add(token); //wse3.0
//Get the SoapContext for the SOAP request that is being made to the Web service.
Microsoft.Web.Services3.SoapContext requestContext = c1.RequestSoapContext;
//Add the UsernameToken to the WS-Security SOAP header.
requestContext.Security.Tokens.Add(token);
//Encrypt the UsernameToken in the WS-Security SOAP header.
//X509SecurityToken serverToken = GetSecurityToken();
//requestContext.Security.Elements.Add(new EncryptedData(serverToken, "#" + token.Id));
//Create a new instance of the MessageSignature class by using
//the UsernameToken just added to the WS-Security SOAP header.
MessageSignature sig = new MessageSignature(token);
//Add the digital signature to the WS-Security SOAP header.
requestContext.Security.Elements.Add(sig);
//Specify the time-to-live (TTL) for the
//SOAP message to diminish the chance of someone
//intercepting the message and replaying it.
requestContext.Security.Timestamp.TtlInSeconds = 120;
//Call the Web service.
//c1.UploadEmployeesRecordToGetRSANos(record, 0023);
try
{
string r = c1.TestPenComService(); //test version
}
catch (Exception g)
{
MessageBox.Show(g.Message);
}
}
On trying to connect to a test method, the respose I get back is:
Microsoft.Web.Services2.Security.SecurityFault: The security token could not be authenticated or authorized ---> System.Exception: WSE563:
The computed password digest doesn't match that of the incoming username token.
at Microsoft.Web.Services2.Security.Tokens.UsernameTokenManager.VerifyHashedPassword(UsernameToken token, String authenticatedPassword)
at Microsoft.Web.Services2.Security.Tokens.UsernameTokenManager.VerifyPassword(UsernameToken token, String authenticatedPassword)
at Microsoft.Web.Services2.Security.Tokens.UsernameTokenManager.VerifyToken(SecurityToken securityToken)
at Microsoft.Web.Services2.Security.Tokens.SecurityTokenManager.LoadXmlSecurityToken(XmlElement element)
--- End of inner exception stack trace ---
at Microsoft.Web.Services2.Security.Tokens.SecurityTokenManager.LoadXmlSecurityToken(XmlElement element)
at Microsoft.Web.Services2.Security.Tokens.SecurityTokenManager.GetTokenFromXml(XmlElement element)
at Microsoft.Web.Services2.Security.Security.LoadToken(XmlElement element, SecurityConfiguration configuration, Int32& tokenCount)
at Microsoft.Web.Services2.Security.Security.LoadXml(XmlElement element)
at Microsoft.Web.Services2.Security.SecurityInputFilter.ProcessMessage(SoapEnvelope envelope)
at Microsoft.Web.Services2.Pipeline.ProcessInputMessage(SoapEnvelope envelope)
at Microsoft.Web.Services2.WebServicesExtension.BeforeDeserializeServer(SoapServerMessage message)
Magic has often been thought of us the art of making dreams come true; the art of realizing visions. Yet before we can bring birth to the vision we have to see it.
|
|
|
|