|
Colin Angus Mackay wrote: Incorrect. Here is what reflector has to say on the subject:
public static readonly string Empty;
That means there is only one representation ever in memory. It is not copied, it is referenced. That means they will ALL point to the same memory address.
Yes I am agree with you.
string s = ""; will create an object in the memory
string s = String.Empty; will NOT create any object, its just a reference.
I also found this on MSDN :
Framework 3.5
((object)"") == String.Empty :::: False
("") == String.Empty :::: True
Framework 1.1 & 2.0
((object)"") == String.Empty :::: True
("") == String.Empty :::: True
Thanks for pointing out the mistake. from now onwards i will use String.Empty to save memory overhead.
|
|
|
|
|
Great Rutvik!
I think all references to String.Empty are pointing to the same memory address, where the static member of Empty locates, right?
regards,
George
|
|
|
|
|
Thanks for your attention, Colin!
1.
What do you mean "It is not copied, it is referenced"? Could you show some pseude code please?
2.
"create two different reference type variables and they have same memory reference" -- sorry I do not agree, here is an example, you create a base type variable (reference type) and a derived type variable (reference type), they are of different types but pointing to the same memory address. Please feel free to correct me if I am wrong.
regards,
George
|
|
|
|
|
George_George wrote: What do you mean "It is not copied, it is referenced"? Could you show some pseude code please?
You have two types of objects. Value types and Reference types. Value types are always copied when you pass them around. Reference types are always passed by reference.
You can think of references in code like the references in academic papers. When you read an academic paper you may come across a reference that reads like this [GoF1994]. When you turn to the end of the paper you will see listed all the references. The reference [GoF1994] may be used several times throughout the paper, but it always points to the same item in the list at the end.
If it was copied all the time you wouldn't have a reference and you would have stuff like this copied throughout the paper [Gang of Four, Effective Design Patterns, 1994, Addison Wesley]. By copying the source paper everywhere the academic paper just got much larger. However, a reference can be used to quickly note what academic paper is being used as the source. The reference points to the full detail somewhere else rather than have the full detail repeated constantly.
|
|
|
|
|
Thanks Colin!
Your reply is clear.
regards,
George
|
|
|
|
|
George_George wrote: "create two different reference type variables and they have same memory reference"
This comment was not made by me.
George_George wrote: you create a base type variable (reference type) and a derived type variable (reference type), they are of different types but pointing to the same memory address
You have not said what you are assigning to these reference type variables. If it is one existing object that you are assigning to both objects then yes they will point to the same memory.
|
|
|
|
|
Thanks Colin!
Your reply is clear. Cool!
regards,
George
|
|
|
|
|
George_George wrote: I am doing input parameter checking for a string type, and string value except empty is valid. My function is provided to outer client to call. Sometimes I find to check null is not enough, I also need to check String.Empty.
Apart from your original question, you might also use String.IsNullOrEmpty[^] for this task.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks Greeeg,
Good to learn from you about the new API!
regards,
George
|
|
|
|
|
hi,
I have one table, inside this i have one server td.
Now i want to change the table cell background color dynamically i.e from the codebehind page.
If i am giving like this
First.BgColor = System.Drawing.Color.Green.ToString();
here First is my cell id.
But it is not effecting.
can anybody knows the solution, please let me know
Thanks and Regards
Dayakar D.N
|
|
|
|
|
Try another forum. This is for C#.
|
|
|
|
|
how can I get a running process start-path?
|
|
|
|
|
In the System.Diagnostics namespace, take a look at Process.MainModule.
|
|
|
|
|
What do you know about the process?
If it is the process that launched your code you can use Application.ExecutablePath
You can also use Process class.
If that doesn't help, then try this: Finding Windows Executable[^]
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Hello
I'm working on web application in VS 2005. I need to create well formatted
word document report(word file has tables).
How it should be done?
I simply dont know anything about creating and writing to word document thru c#/vb/ crystal report.
Please someone tell me how to deal with this.
TIA,
Leena
|
|
|
|
|
Hi All,
I'm trying to build some reporting into an app that I've been working on for a while.
The app has a range of class objects in memory, which I want to use to populate the report. In short, I want to push the data to the report at runtime.
I have designed the report structure (and created the .rdlc file), added a report viewer and bound the viewer to the report. However, I cannot seem to access the objects in the report for assignment.
All net searches return info on binding to database tables, but I've found nothing on binding to class objects.
Any ideas / pointers?
Thanks in advance,
John.
|
|
|
|
|
Open the .rdlc file and you should now have a Data menu item in the VS menu. Click Add New Data Source, select Object and go through the wizard.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
Hi Scott,
I can do that, but once a class is in my data sources tab, I can't look at the componants and can't attach them to a part of my report.
In addition, a lot of the data items I have are time-series items. I will want to set a date for the report and include only data items up to that date. Is there a way to create a dataset in code and dynamically attach it to the report?
Thanks,
John.
|
|
|
|
|
If you have your report active in a tab, you should have a Report menu item. You have to use that to add sources to the particular report. Then you should have them as choices when you put components down on the report. If you didn't know already, you have to pass data in as a generic list even if there's only one object that you're working with. And be warned that the editor is NOT NICE when it comes to revising the report, I can't tell you how many times I've had to manually edit the rdlc file to fix something that the automation broke.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
Hi,
I've got this piece of code:
Assembly asm = Assembly.LoadFrom(@"C:\Documents and Settings\someDll.dll");
Type type = asm.GetType(someClass);
How can I instantiate a list for the type found above? something like (doesn't work):
System.Collections.Generic.IList<type> list = new System.Collections.Generic.List<type>();
Thanks in advance
|
|
|
|
|
Member 3754905 wrote: How can I instantiate a list for the type found above? something like (doesn't work):
I am not sure I got your question, are you looking to instantiate the type ? Try Activator.CreateInstance()
|
|
|
|
|
No, I've got the type.
I want to make a generic list that contains objects of the type I just found. E.g.:
List<typefound> list = new List<typefound>();
|
|
|
|
|
If the generic type has a default constructor (zero-arg), then all you need do is add a constraint to handle it. Consider this example:
public class CreatableTest<T> where T : new()
{
public static T CreateTestObject()
{
return new T();
}
} The section where T : new() adds the ability to call the default constructor.
|
|
|
|
|
That wont work The type is not known at compile time.
|
|
|
|
|
leppie wrote: That wont work The type is not known at compile time.
Sorry, but it is. Try this sample:
using System;
using System.Collections.Generic;
using System.Text;
namespace MyClass
{
public class Class1
{
public static T Create<T>() where T : new()
{
return new T();
}
}
public class MyTest
{
public MyTest()
{
}
}
} This can be called by:
using System;
using System.Collections.Generic;
using System.Text;
namespace TestHandler
{
class Program
{
static void Main(string[] args)
{
MyClass.MyTest test = MyClass.Class1.Create<MyClass.MyTest>();
if (test != null)
Console.WriteLine("Here I am");
Console.ReadLine();
}
}
} Works fine - it's not useful because other constraints would be useful such as constraining it to a type to get default information.
|
|
|
|