|
I am sure there is no need to shout. To export data to excel look up
ADO.Net or
Excel Interop . to export data to pdf try iTextSharp library. In future you don't need to use bold letters. Most people in these forums can read quite fine.
|
|
|
|
|
For Excel, just put it on the clipboard. (DataGridView.GetClipboardContent.)
For PDF there is no obvious meaning for what you want, never mind a method to do it. PDF is a display format not a data table one. If you want to create a PDF which has within it some text and lines that makes it look like a table, you can do that yourself (or find a library that does it).
|
|
|
|
|
Hi,
I have two classes say Class A and Class B. I am trying to find how
do I get reference the loaded instance of Class A in Class B.
I do not want to get a new instance of Class A. I want to be able to
reference to the loaded instance and use the loaded methods and properties.
Class A
{
...
Class A myClass = New Class A();
...
...
Class B clsb = New Class B();
clsb.DoSomething(int a, int b)
}
Class B
{
...
public void DoSomething(int a, int b)
{
....
//I want to be able to reference to the loaded instance which is 'myClass' of the Class A. (not a new instance)
}
}
Can some one please help me with this.
Thanks,
L
.
|
|
|
|
|
|
ClassA should provide a static method or a static property which returns the instance created inside it. This method/property will help others access that instance.
|
|
|
|
|
If having a static reference (or the Singleton pattern, basically the same thing) is inappropriate, you could pass it in in the constructor or as a method parameter on class B.
I'm surprised this works, though - maybe it's the pseudo-code you've presented, but this:
public class ClassA()
{
private ClassA myClass = new ClassA();
}
is the same as:
public class ClassA()
{
private ClassA myClass = null;
public ClassA()
{
myClass = new ClassA();
}
}
Won't this end up with a stack overflow?
|
|
|
|
|
GlobX wrote: Won't this end up with a stack overflow?
Why not just run it and see for yourself. I guess it will.
|
|
|
|
|
It was more intended as a rhetorical question, like a "have you thought about this...?" 'sides, too busy hating on BizTalk to play around
|
|
|
|
|
GlobX wrote: hating on BizTalk
Just work on SharePoint as well and you have witnessed hell.
|
|
|
|
|
Pass it to the constructor or a property.
B b = new B() ;
A a = new A ( b ) ;
or
a.B = b ;
|
|
|
|
|
Hi,
You need to use the Singleton pattern to achieve this. Please find the example below
public class A
{
private static A _instance;
private A()
{}
public static A GetInstance()
{
if(_instance == nulll)
_instance = new A();
return _instance;
}
}
public class B
{
public void Somemethod()
{
A a = A.GetInstance();
.
.
.
do somethig
.
.
}
}
Note that we make the constructor of class A private. And class A holds a instance of itself in _instance variable. This is for to make sure that an out side method cannot create an instance of A. Then we will provide a static method in class A like GetInstance where we create a new instance if an instance is already not exist and return the current instance
Hope this helps
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
No, never a singleton, especially with .net languages; they're not needed and generally a symptom of poor design. I have never found a situation that wuold benefit from a singleton.
Nitheesh George wrote: cannot create an instance of A
In .net everyone has access to your privates.
And give this[^] a read.
|
|
|
|
|
Hi,
I want to separate number and date and time from a string in c#. here is an example:
+CMGR: "REC READ","+923365483536",,"10/09/15,08:16:11+20"
from this i want to put cell number in one array and date and time in another.I dont know how to do this.
Thanks for any kind of help in advance
Regards,
Aeman
|
|
|
|
|
Well, you could always use a string split on this based on the commas and take the array items at index 1 and index 3.
|
|
|
|
|
index 3 and 4!
I cannot remember: What did I before google?
|
|
|
|
|
So cell isn't stored in the bit +9....? Index 3 is an empty string in his example.
Nevermind - I see what you're saying. I'd missed the , in the date.
I'm not a stalker, I just know things. Oh by the way, you're out of milk. Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Onyx
modified on Tuesday, March 29, 2011 9:40 AM
|
|
|
|
|
You could use a regular expression but then you may end up with not one problem but two
using System.Text.RegularExpressions;
...
string txt = "+CMGR: \"REC READ\",\"+923365483536\",,\"10/09/15,08:16:11+20";
Match m = Regex.Match(txt, @"[0-9]{2}/[0-9]{2}/[0-9]{2},[0-9]{2}:[0-9]{2}:[0-9]{2}");
if(m.Success)
{
String date = m.Value.Replace(",", " ");
DateTime dt = DateTime.Parse(date);
}
The snippet above should work but you may want to refine the expression. I just hacked that one up quickly
"You get that on the big jobs."
|
|
|
|
|
May I humbly suggest Rive[^]?
|
|
|
|
|
Try to use regular expression,MAN.
Hope this helps.
Hi, i am from china.Like to make friends with you from all of the world.
|
|
|
|
|
It's very easy
First store the entire string in a string variable
and then use the split method and assign it to a character array
split(",,")
and from that array fetch the appropriate value like
string s="+CMGR: "REC READ","+923365483536",,"10/09/15,08:16:11+20";
char[] temp=s.split(",,");
now your temp[1] consists both time and date.
if you want separate both use the same technique.
|
|
|
|
|
Hi,
I get a program c# when googling that validates the IBAN :
static bool isIban (string code_iban)
{
code_iban = code_iban.ToUpper () ;
StringBuilder sb = new StringBuilder ();
foreach ( char car in code_iban)
{
if (char.IsDigit (car) || char.IsLetter (car))
sb.Append (car);
}
code_iban = sb.ToString ();
if (code_iban.Length < 15 || code_iban.Length > 34)
return false;
string iban = code_iban.Substring(4, code_iban.Length - 4) + code_iban.Substring(0, 4);
StringBuilder sb2 = new StringBuilder ();
foreach (char c in iban)
{
int entier;
if (char.IsLetter(c))
entier = Convert.ToChar (c) - Convert.ToChar ("A") + 10;
else
entier = Convert.ToChar (c) - Convert.ToChar ("0");
sb2.Append (entier);
}
string checkSumString = sb2.ToString();
int checksum = int.Parse(checkSumString.Substring(0, 1));
int i = 1;
while (i < checkSumString.Length)
{
int v = int.Parse(checkSumString.Substring(i, 1));
checksum *= 10;
checksum += v;
checksum = checksum % 97;
System.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1);
}
if (checksum == 1)
return true;
else
return false;
}
}
I understand all only the functionality of System.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1);
ty
|
|
|
|
|
Well, Math.Max is retrieving the maximum of i or i-1. Interlocked.Increment is used to increment i and store it all as an atomic action.
|
|
|
|
|
Hi,
If u can give me the // algorithme of this.I can do this like this simply
Math.Max( ref i , i-1)
i ++;
why using of Interlocked.Increment???????
ty
|
|
|
|
|
You shouldn't. In this case, it's absolutely no use whatsoever - frankly, it looks like somebody is trying to be too clever for their own good. Interlocked increment only makes sense in multi-threaded scenarios where there is a possibility that somebody else may increment a shared variable. As i is local, it's pointless. This code looks like obfuscation through stupidity.
|
|
|
|
|
Pete O'Hanlon wrote: obfuscation through stupidity
5
|
|
|
|