|
Hey there
thanx for the the suggestion, which namespace mast i reference to get Marshal? All i see in intellisence is MarshalByRefObj
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Harvey,
It's found in the namespace System.Runtime.InteropServices
Update on the pattern:
SomeInteropClass sic = null;
try
{
sic = new SomeInteropClass();
}
finally
{
if (sic != null) Marshal.ReleaseComObject(sic);
}
Good luck!
|
|
|
|
|
i am working with a crystal report and i have got a problem. IN the given below code i'm mapping formulafield ["HOTEL_SRV_TEXT"] WITH sParaFormula[10] which is an array and its value comes from the particular array. for example when the value of sParaFormula[10] is something like "balligo" it works but if the its value is "balli's" then it does not work...
if there is character like " ' " then it does not work.....
could any body help
RptSrvName.DataDefinition.FormulaFields["HOTEL_SRV_TEXT"].Text = "'" + sParaFormula[10].ToString().Trim() + "'";
|
|
|
|
|
I'm working on an application wich recieves an fax and will display the fax as an .TIFF in an image component.
But the problem is i cannot get it to work . The idea is to when an fax arrives it appearse in an grid and can be selected then either removed, opened or re-send to an email. I'm looking for someone who can help me complete this task. the programe it self is alomst finished except for that part.
Any help suggestions or code is greatly appriciated
|
|
|
|
|
Try www.rentacoder.com or advertise this position on the jobs forum.
|
|
|
|
|
Gebruik je TAPI 3.0?
en een TIFF sla je op een locatie op een shcijf op. Als je van die locatie een URI maakt en je het webbrowser component gebruikt, dan toon je de tiff als webpage.
via SMTP class kun je een mail met HTML opmaak sturen!
|
|
|
|
|
De .TIFF wordt geopent in ImageEn van HiComponent dat werkt.
Alleen ik krijg het niet voor elkaar om de DataGridView de directory te laten zien. Waar uit de Files geselecteerd kunnen worden en geopend worden in de IeMulti (waar de tiff als ut meerdere afbeeldingen zijn te zien zijn)
Het probleem zit me bij de DataGridView die moet de directory lezen en de lijst met files laten zien + het soort file bijv. .jpg datum van waneer het is binnengekomen of gemaakt bestands groote enz.
Meest van het programma is er al alleen de DataGridView niet
|
|
|
|
|
I need to know what is Hashtables? and how it is used. Plz give me some examples
Regards,
LEE
|
|
|
|
|
|
A hashtable is a glorified array
Instead of having an index and value you have a key and a value, so you can specify the index as "myKey" for example and get the value for it like so... myHashTable["myKey"]
The other advantage is that a hashtable can grow indefinitely (until ram runs out)
To iterate Though each entry in a hash table do this foreach (DictionaryEntry de in myHash)
Hope it helps
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Hi friends..
I am using bitmap to draw graphics object...How can i perform cut ,delete function ...
currently i done cut, Delete, zoom operation by the following way
for cut and delete
1)Delete the particular graphics object in storage and redraw the remaining graphics object
for zoom
2)Creating new bitmap based on zoom level and redraw all the graphics object..
|
|
|
|
|
Hi,
Can anyone please tell me the difference between virtual function Equals(), static function Equals() and Static function ReferenceEquals() defined in Object class. I searched a lot, but didnt get a clear idea about their differences. Am confused with these three. Can anyone give a small example with the output in these 3 cases.
Regards
modified on Wednesday, April 2, 2008 2:10 AM
|
|
|
|
|
Darmi wrote: difference between virtual function Equals(), static function Equals()
Virtual function Equals(object) checks the current instance with the supplied instance. Consider the following code
MyClass obj1 = new MyClass();
MyClass obj2 = new MyClass();
bool b = obj1.Equals(obj2); here obj2 will be compared with obj1 .
Static Equals(object1,object2) checks the supplied instances (object1 and object2 here).
MyClass obj1 = new MyClass();
MyClass obj2 = new MyClass();
bool b = MyClass.Equals(obj1,obj2);
Darmi wrote: Static function ReferenceEquals()
This checks the the supplied object instances are having same reference.
|
|
|
|
|
When you call Object.Equals(o1, o2) the static version, internally that function first checks to see if the references are not null, and then calls the virtual method o1.Equals(o2). I just checked that using Reflector so that's accurate. Now here's where it can get tricky, if you do not override the Equals method, when o1.Equals(o2) is called in the static function, it just checks object references. I'm going to repost the code that I previously posted.
namespace PersonTest {
class Program {
static void Main(string[] args) {
Person p1 = new Person { Member = "ABC", OtherMember = 1 };
Person p2 = new Person { Member = "ABC", OtherMember = 1 };
Console.WriteLine(Object.Equals(p1, p2).ToString());
Console.WriteLine(Object.ReferenceEquals(p1, p2).ToString());
Console.ReadLine();
}
}
public class Person {
public String Member { get; set; }
public Int32 OtherMember { get; set; }
public override Boolean Equals(Object obj) {
return obj is Person ? Equals(obj as Person) : false;
}
private Boolean Equals(Person obj) {
if (Object.ReferenceEquals(this, obj)) return true;
if ((obj == null) || (this == null)) return false;
return obj.Member == this.Member && obj.OtherMember == this.OtherMember;
}
public override int GetHashCode() {
return base.GetHashCode();
}
}
}
Put this into a project and the output will be True False. Then comment out both of the Equals methods in the Person class and the output will be False False. The reason is that you have 2 different references to Person classes. Regardless of the EQUALITY of the classes the IDENTITY will always be different. Object.ReferenceEquals is always IDENTITY. Object.Equals starts by checking EQUALITY, but then defaults to IDENTITY in the absence of an overridden Equals() method in your class. That's why when you comment out the Equals methods in the Person class, the Object.Equals(p1, p2) the method goes to IDENTITY and not EQUALITY. You have to supply the EQUALITY.
I hope this rather thorough explanation helps.
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Working in C# ASP.NET 2.0
I am new to C# development, looking to get the unique key for a user to use as a foreign key in other tables.
I must be missing something, but is there a way to get this without a query to the asp_net Profile table?
Thanks.
|
|
|
|
|
Alright now I have a really strange bug thats popping up in my code.
Some Before hand details.
Language: C#
Framework Version: 2.0
IDE: Visual Studio 2008 Team Edition
Now to the real problem
I'm working on a project and because it is based on a plugin engine I have to pass the current context of the system to the plugin. So
I use the Singleton Pattern alot. Basic snippet below.
public class SomeClass
{
private static SomeClass _current = null;
public static SomeClass Current
{
get
{
if(_current == null)
{
_current = new SomeClass();
}
return _current;
}
}
public SomeClass()
{
}
}
Now that seems pretty normal and correct to me but this is how it executes. Just watch the little arrow.
public class SomeClass
{
private static SomeClass _current = null;
--> public static SomeClass Current
{
get
{
if(_current == null)
{
_current = new SomeClass();
}
return _current;
}
}
public SomeClass()
{
}
}
Ok good so far.
public class SomeClass
{
private static SomeClass _current = null;
public static SomeClass Current
{
get
--> {
if(_current == null)
{
_current = new SomeClass();
}
return _current;
}
}
public SomeClass()
{
}
}
Still ok
public class SomeClass
{
private static SomeClass _current = null;
public static SomeClass Current
{
get
{
--> if(_current == null)
{
_current = new SomeClass();
}
return _current;
}
}
public SomeClass()
{
}
}
Alright we are there..
public class SomeClass
{
private static SomeClass _current = null;
public static SomeClass Current
{
get
{
if(_current == null)
{
_current = new SomeClass();
}
--> return _current;
}
}
public SomeClass()
{
}
}
Thats right.. It evaluates _current == null as false but clearly I have it assigned to null.. and it never executes my constructor.
So I have no idea whats going on.
By the way this happens in a .DLL thats being referenced by a web project and I first noticed this issue when testing out a class with one
of my unit tests.
So basicly what I'm asking is if someone with more knowledge than me can help me figure out whats going on cause no matter what I do it always seems to skip that _current = new SomeClass() statement.
But whats even more confusing is I have another class thats exactly the same (except the named of course) and it executes and works fine. So I dont know.<
|
|
|
|
|
I was interested by this one so I thought I'd try it out. My full code is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
SomeClass theClass = SomeClass.Current;
theClass.RunMethod();
Console.ReadLine();
}
}
public class SomeClass
{
private static SomeClass _current = null;
public static SomeClass Current
{
get
{
if (_current == null)
{
_current = new SomeClass();
}
return _current;
}
}
public SomeClass()
{
Console.WriteLine("Constructor");
}
public void RunMethod()
{
Console.WriteLine("Method");
}
}
}
As you'd expect, when I run this, it prints out both strings. So then I started to debug it to see what was happening. As I debugged, I hovered my mouse over the various variables as I always do to check the state of things, and lo and behold, it skipped straight over the if statement just like you described, and I realised what might be happening.
SomeClass.Current is a static member that creates the instance the first time it is called. That can include being called by any attached debugger trying to look at the static member, so when I hovered my mouse over the SomeClass.Current bit, that action kicked off the constructor, so when I stepped into the routine it had already run.
The really interesting thing about this is that if you stick a break point in the constructor it never gets hit! The Visual studio debugger must disable break points when it runs code for property evaluation.
I suggest you have a look in your watch window and see if you've got a watch on the static member that will be having the effect of calling the constructor. You could also try sticking a Debug.WriteLine in the constructor and check that it does indeed output something.
(Incidentally, you should bear in mind that your singleton isn't thread safe. It might not matter for your use, but you should take a look at this article for a discussion of the singleton pattern in c# http://www.yoda.arachsys.com/csharp/singleton.html[^])
Simon
|
|
|
|
|
I think Simon has probably nailed this, but why bother checking for null in the first place. Static constructors only get called once so you can infer it will always be null when you get there.
It's a good pattern for Singletons. Threadsafe to boot as well.
Regards,
Rob Philpott.
|
|
|
|
|
Right Scrubb that. I was being thick and thinking the construction was done in the constructor. Which I presume it isn't to make it lazier.
Regards,
Rob Philpott.
|
|
|
|
|
The issue is the static member variable. You should probably declare it private readonly and not static. What you are trying to do with the singleton pattern is force one instance in your application. static classes do that, and if your SomeClass has no internal state, then you should move it to a static class instead. If you insist on keeping the member static, then put the initialization into a static constructor and don't check ==null in the Current property.
public class SomeClass {
private readonly SomeClass _current;
public static SomeClass Current {
get {
if(_current == null) { _current = new SomeClass();}
return _current;
}
}
public SomeClass() {
}
}
public class SomeClass {
private static SomeClass _current;
static SomeClass(){
_current = new SomeClass();
}
public static SomeClass Current {
get {
return _current;
}
}
public SomeClass() {
}
}
Hope that helps.
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Thank you all for helping cause I was going insane trying to figure out why this was happening. It was so very annoying.
By the way Simon thank for the thread safety tip.
|
|
|
|
|
Hi.. i'm making a program and this is how it goes..
I have actually two buttons and having the same event handler... how will i know which button triggered the event?.. what i was planning to do is just to pass a parameter to the method but it seems like the only parameters that is only allowed is the (object sender, EventArgs e)... am not that really proficient in C# so i guess you could give me solutions and workarounds on how to do this
|
|
|
|
|
The object 'sender' is the button that triggered the event.
just cast it to button type and check if it is the one you require.
e.g.
Button b = sender as Button;
if(b == button1)
.....;
else ...;
or you could assign a value in the "Tag" property of the button and check it in the event handler.
regards
|
|
|
|
|
Thanks a lot.. can i also cast like using the java syntax like
"Button b = (Button) sender" <--- is that possible?
|
|
|
|
|
Silvyster wrote: is that possible?
Did you try it? What happened?
|
|
|
|