|
abdelhameed81 wrote: how to use constructors
See the program class to see how to use constructors
public class A
{
private string myText;
public A(string someText)
{
this.myText = someText;
}
public void WriteMyText()
{
Console.WriteLine(someText);
}
}
public class Program
{
public static void Main()
{
A a = new A("Hello World");
a.WriteMyText();
}
}
abdelhameed81 wrote: why do we use them regarding the idea that we can initialize our variables in any section without using constructors.
Because it is good practice to initialise the fields to something sensible. The CLR will initialise the fields to default values if you don't set them. e.g. an int will be set to 0 , a string to "" and so on. But they may not be sensible for your application.
In objects that are immutable there is no opportunity to set the fields after the constructor has setup the object. The very nature of an immutable object is that it does not change. So it MUST set the class fields at construction. For example the string class is immutable, you cannot change a string object, you can only create new string objects.
Sometimes you may have a situation where a field is a lazy lookup because it isn't used often and it takes a long time to retrieve the value. In that case it would be initialised to null (if it is a reference type) and the getter property would do the lookup and cache the value in the field when it has been retrieved.
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
Colin Angus Mackay wrote: The CLR will initialise the fields to default values if you don't set them. e.g. an int will be set to 0, a string to "" and so on.
A slight correction, just to avoid misunderstandings:
A string will be initialised to null, not to an empty string.
---
b { font-weight: normal; }
|
|
|
|
|
A construtor is always used to create an object. If you don't declare a constructor for a class, an empty constructor is created.
As there always is a constructor, it's a sensible place to initialize the data in the object. That way it's impossible to forget to initialize it.
---
b { font-weight: normal; }
|
|
|
|
|
hi,
i am using TAPI3 for outgoing call, i make call but the problem is how do i know whether otherend has picked up the phone or not because when phone is picked up by someone i want to play audio.
|
|
|
|
|
I'm trying to do the same thing from the scartch can you give me a sample code or something like that to call a number in a C# from ...
Thanks
|
|
|
|
|
I also want to do it. Please guide me or give some code for demonstration purposes. I'll be so thankful to you.
Best Regards,
Rizwan
|
|
|
|
|
i am in a project containing a part that give someone a call
will you give me a sample code too in C#
|
|
|
|
|
I don't hav such code ...
what language are you using ?
Mr.K
|
|
|
|
|
Hi,
Can We detect Sql Servers on Network using c#
Like when we reister new conection sql server it shows the list of all server in the network.
This is same i need to do in my c# product installer.
Thanx & Regards
Anuj Kamthan
Software Developer
Solversa Technologies,
Pune - 411007, India.
http://www.solversa.com
|
|
|
|
|
Hi, I am trying to develop an ActiveX control in C# that changes the text of the textboxes on the client machine...for this purpose...i got the code, that closes a window using the window name and the class name in a WINDOWS FORM.
class Win32{
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
[DllImport("user32.dll")]
public static extern int FindWindow(
string lpClassName, // class name
string lpWindowName // window name
);
[DllImport("user32.dll")]
public static extern int SendMessage(
int hWnd, // handle to destination window
uint Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);
}
// Determine the handle to the Calculator window.
int i=Win32.FindWindow(txtClsNm.Text ,txtWndNm.Text);
// Post a message to Calc to end its existence.
int j=Win32.SendMessage(i, Win32.WM_SYSCOMMAND, Win32.SC_CLOSE, 0);
However, when i tried to use the same in an activex control, it gave me a security exception...
************** Exception Text **************
System.Security.SecurityException: System.Security.Permissions.SecurityPermission
at ActiveXDotNet.myControl.button2_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
The type of the first permission that failed was:
System.Security.Permissions.SecurityPermission
The Zone of the assembly that failed was:
MyComputer
Can anyone tell me how to solve this problem...ideally tell me the API call that helps me CHANGE the text box contents at the client machine...
just in case ,it helps, to develop an activex control in .NET, i created a "Class Library" project and put a "User control" over it...
PLEASE help!!
thanx
Wajih
|
|
|
|
|
Hello
How can i create class libraries that can be used only in my program.
Thanking You
Navaneeth
|
|
|
|
|
I don't think there is any mechanism which prohibits other programs to use your class library.
As a thought, what can be done is have a sort of login functionality in your class library. I mean, before anyone can use any of the functions in your class library, they have to first login to your class library. Create a function known as login, which takes a username and a password. If the username and the password are correct, set an internal flag to true. Now when other functions are being called, check for the internal flag! If the internal flag is false, don't execute the function, if it is true then go ahead as it normally would.
bool blnValidUser = false ;<br />
<br />
bool LoginUser( string strUserName, string Password )<br />
{<br />
if( username and password match )<br />
{<br />
blnValidUser = true ;<br />
return true ;<br />
}<br />
else<br />
{<br />
blnValidUser = false ;<br />
return false ;<br />
}<br />
}<br />
<br />
void function1()<br />
{<br />
if( blnValidUser is true )<br />
{<br />
Go ahead as planned.<br />
}<br />
else<br />
{<br />
return ;<br />
}<br />
}
Hope this helps!
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
Hi Experts
I am developing a security system for my software. One copy of product has to be installed only on one pc. So i tried to create a unique system key according to processor id or MAC address. But this is not common, some processors may not have serial no's and more over this will not work with XP and 2000. So anyone suggest a nice tip for providing security and preventing piracy ?
Cheers
Navaneeth
|
|
|
|
|
Even giants like MicroSoft haven't been successful in curbing piracy.
Why don't you try a commercial licensing product like Software Shield[^]? One of my clients has used it and they say its great.
All the best!
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
How can I get the bits that compose a byte?
Say I pass a byte of value 10 to my byteToBitArray function, I would
LIKE to get back an array (8 long) of 00001010.
I want that back cause that's the binary representation of the byte 10.
Any idea how to do this?
|
|
|
|
|
Hi,
here a small sample how to build a string representation:
private string Convert(byte b)
{
int curVal = 256;
string temp = "";
while (curVal > 1)
{
curVal /= 2;
if (b >= curVal)
{
temp += "1";
b -= (byte)curVal;
}
else
temp += "0";
}
return temp;
}
It could easely be modified to return a bool array or whatever you need exactly.
|
|
|
|
|
I found an easier solution. I can just load my bytes into the BitArray class!!!
/\ |_ E X E GG
|
|
|
|
|
Well I thought there should be an easier way but I was in playing mood...
|
|
|
|
|
|
I implement Project to GIS(ESRI) and use C#, I used Map Control view Detail Map on Form.
How wiil I do Use algorithm "Floyd" find the fastest/shortest way the two places
Can U share Code or Exameple for Me (send to dong.nguyendinh@yahoo.com)
Thanks very much
AnhTin
|
|
|
|
|
Why don't you ask the ESRI guys. You have paid for their stuff, haven't you?
|
|
|
|
|
hi,
I am looking for replacing my background color winform by my input video.
How can I do this ?
best Regards
youssef
|
|
|
|
|
With difficulty
Your best bet would be to embed a media player like the Windows Media Player control thingy in your application (just drop the control on the form) and use that, otherwise you'll have to deal with decompressing the video, converting it to a displayable format, drawing it on the form, as well as dealing with trying to optimize it so that the video displays in it's realtime.
At least with an embedded control then the majority of stuff is native code and will be faster and also the drawing will be done by Win32 rather than GDI+ so will be faster as well.
You could do what you want if you know how to decode the video but it probably won't be displayed in realtime.
Sorry to burst your bubble
Ed
|
|
|
|
|
Having issues find solution in for Remote Registry editing.
Yeah i got the remote viewing under control...
With remote editing, I can do it with VBscript easy:
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")<br />
objReg.SetStringValue HKEY_LOCAL_MACHINE,strPointerKey,strPointerEntry,strPointerValue<br />
objReg.CreateKey HKEY_LOCAL_MACHINE,strMyKey
surely .NET can do it. this is what i tried:
RegistryKey LM = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,WSID);<br />
RegistryKey inventoryKeys = LM.OpenSubKey("SOFTWARE\\CompanyName\\AppName");<br />
inventoryKeys.SetValue("ValueName","Value");
and the error message is:
Get REG values: System.UnauthorizedAccessException: Cannot write to the registry key.
at Microsoft.Win32.RegistryKey.ValidateState(Boolean needWrite)
at Microsoft.Win32.RegistryKey.SetValue(String name, Object value)
at testReg.Class1.update() in c:\projects\testreg\class1.cs:line 48: 03/24/20
06 02:41:01 PM
|
|
|
|
|
I thought the error was pretty clear. The account your code in running under (probably yours) doesn't have write permissions to the key you opened.
Are you running in a domain environment?
Does the account you're using have Administrator rights to the remote machine?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|