Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have an abstract class which name is abclass,
why i cant create an object like
abclass ab1 = new abclass();
from main
I have constructor in abclass also.
You cannot create an instance of an abstract class.
If you don't provide an implementation for some methods on your abstract class, it cannot, obviously, work.
I suggest you Google 'abstract classes' for more information.
If you want to instantiate your class, remove the abstract keyword.
Read about "Abstract Classes" in MSDN
It is beautifully explained !!!!
The reason is: Abstract class can not be instantiated .
Lets do some basics here:
check http://msdn.microsoft.com/en-us/library/ms173150.aspx
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
I create a new DataContract and I need to add a new field.
That field will be describe a type of export job: Ad-hoc or virtual standby.
Which type do I need to choose to represent this idea: bool or enum? Why?
Consider how it will be used as method parameter
void F(DataContract dataContract)
If it's Enum, you invoke it via
F(DataContract.AdHoc)
F(DataContract.VirtualStandby)
They are all very clear. What if it's bool:
F(bool dataContract)
Then invoke it via
F(true)
Execute me! Is it Ad Hoc or Virtually Standy? You have educate every method consumer what true/false mean in this context. Even they want to write clear code by
F(true/*Ad Hoc*/);
It's really less readable.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have got a list of PropertyInfo, now i need to either populate a new object with these propertyinfos and there values or generic a type runtime containing these properties so i can create a new instance of the object based on my runtime created type.
I cannot create a new instance of an object based on an earlier type because i just filtered out my collection based properties (this is due to serialization of an object; long story).
How can i achieve this?
I think TypeBuilder will suit your needs.
On the bottom of the page you will see a clear example.
Also if you need to build methods use Expression Trees instead of ILGenerator.
Here's a few options:
Use TypeBuilder to create a runtime type. Use DefineMethodOverride to implement the get/set methods of the properties and return the interface type (with the runtime implementation).
Use one of the many Mock frameworks. They basically do the plumbing for you; the result is the same.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
All in the Title.
Also please give an answer in less than a week.
I need someone to really help me with this, I'm using an online course and it says I have to Write the NumberBoard method, then write a NumberBoard constructer and call the method.
Here's the link to the .zip file that has the PDF telling me what to do, and the project that they give you:
https://d396qusza40orc.cloudfront.net/gameprogramming%2Frequired_assessment_materials%2FRequiredProjectMaterials.zip
(Copy and paste if link not clickable)
To get to the project, open the code folder and click the "GameProject" thing
Something like this will work
public class SomeClass
{
public SomeClass() //constructor
{
SomeMethod(); //Calling the method in constructor
}
public void SomeMethod() // Method
{
//Method implementation
}
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm working on a program and to avoid complication I need to parse a given string variable to be a DirectoryInfo.
I was wondering if it were possible to parse a string to a DirectoryInfo.
If it is, how does one go about doing that?
Thanks
DirectoryInfo di = new DirectoryInfo(string);
MSDN, linked above, provides you the exceptions in case the string is invalid. Note: this is NOT if the directory exists. MSDN also makes note of this in the Remarks. You must then do:
if(di.Exists)
Well, it's not parsing, but the constructor for DirectoryInfo takes the path as a string:
DirectoryInfo di = new DirectoryInfo(#"c:\MyDir");
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to generate a custom xml doc, using this class:
[CollectionDataContract(Name="Applications", ItemName="Application")]
public class ApplicationNamesList : List<string> { }
The xml output im aming at should look like this
<Applications>
<Application>...</Application>
<Application>...</Application>
<Application>...</Application>
</Applications>
But once I have a List<string> object and try and cast this to ApplicationNamesList i get an InvalidCastException.
Is there something basic im not getting here?
A List<string> simply isn't a ApplicationNamesList. You would need to do something like this:
var result = new ApplicationNamesList();
result.AddRange(list);
With list being a List<string>.
Sometimes it helps to use real world examples:
Every Porsche ( => ApplicationNamesList) is a car ( => List<string>). But not every car is a Porsche.