ConsoleApplication2.exe' does not contain a static 'Main' method suitable for an entry point eradicator wrote:
I don't know that you need the string[] args part, but believe you at least need the STAThread attribute applied. Both are actually optional (though for other reasons you have requirements to set [STAThread] or [MTAThread]). When you specify static void Main() you just indicate that you'll just drop any command line arguments. [STAThread] has a counterpart of [MTAThread], in general you'll use STAThread. Tag: Visual C# General Simple Form writting to a csv file. Visual C#

Generics Plese help long discussion sorry ! I wrote the following simple class below to clear up some points.
The class below that is from a book, and I am using it to try and make the code clear to me¡­
Can people please comment on what I am saying, I am sure a lot of it wont be accurate.
My comments:
The class below has a defualt and non default construct used to create instances of the class student.. Without these an object of this type cant be contructed or instaniated.
When this line is called
blank = new student ();
a blank template is created for the student class. Putting a ¡°¡± into the name veriable and zeror into the id¡­
when either property such as myStudent.Name it uses the get to return the value¡­
Now moving onto the Generic class Farm<T>
Where is the defualt construct
private List <T> animals = new List <T>();
this apppears close to it and it appear to me that the property
public List <T> Animals
{
get
{
return animals;
}
}
Animals is being used like a handle to set up the animals collection
Eg..
farm.Animals.Add( new Cow ( "Jack" ));
Animals uses the get to return animals the actual collection for storing the collection of animals
If we substitute animals for Animals we are adding via animals.Add to this collection
Initialy to me, it seems the get should be be a set as this seems to be setting values
I see this simulary to mystudent.Name which is a get to access name, Via Name.
These lines are confusing
public IEnumerator <T> GetEnumerator()
{
return animals.GetEnumerator();
}
I can see it¡¯s a method, and what it returns, there is no yield and its not implemented as in the usual way¡­
Also the line return animals.GetEnumerator(); The book says you simply return the enumerator returned by Animals¡­.
But Farm<T> : IEnumerable<T> inherits from this inteface not Animals
animals is just a type, that contains the collection of animals, I can see you are trying to iterate through it in the foreach loop, but where is it implemented..
should it be (obviously not it wont work) but Farm<T>.Animals.GetEnumerator()
what is this a method a it looks odd the way its defined plus where is it implemented..
thanks Laurence
Also I am aware ArrayList() implements GetEnumerator() as it uses a foreach command.
IEnumerator IEnumerable .GetEnumerator()
{
return animals.GetEnumerator();
}
using System;
using System.Collections.Generic;
using System.Text;
namespace stud
{
public class student
{
private string name;
private int Id;
public student()
{
// default contructor.
}
public student( string newname, int newId)
{
name = newname;
Id = newId;
}
public string Name
{
get
{
return name;
}
set
{
name = value ;
}
}
public int ID
{
get
{
return Id;
}
set
{
Id = value ;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace stud
{
class Program
{
static void Main ( string [] args)
{
student blank = new student ();
student myStudent = new student ( "Frank" , 1);
Console .WriteLine( "{0} is students name {1} is students ID" , myStudent.Name, myStudent.ID);
Console .WriteLine(myStudent.ToString());
Console .WriteLine( "{0} is students name {1} is students ID" , blank.Name, blank.ID);
Console .WriteLine(blank.ToString());
Console .ReadKey();
}
}
}
Generic Class is confusing
using System;
using System.Collections.Generic;
using System.Text;
namespace ch12ex02
{
public abstract class Animal
{
protected string name;
public String Name
{
get
{
return name;
}
set
{
name = value ;
}
}
public Animal()
{
// default constructor
name = "The animal with no name " ;
}
public Animal( string newName)
{
// non defualt contructor.
name = newName;
}
public void Feed()
{
Console .WriteLine( "{0} has been fed." , name);
}
public abstract void MakeNoise();
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace ch12ex02
{
public class chicken : Animal
{
public void LayEgg()
{
Console .WriteLine( "{0} has laid an egg" , name);
}
public chicken( string newName): base (newName)
{
}
public override void MakeNoise()
{
Console .WriteLine( "{0} says Cluck" , name);
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace ch12ex02
{
public class Cow : Animal
{
public void Milk()
{
Console .WriteLine( "{0} has been milked." , name);
}
public Cow ( string newName ): base (newName)
{
//This willl call the non defualt constructor of the base animal class.
}
public override void MakeNoise()
{
Console .WriteLine( "{0} says moo!" , name);
}
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace ch12ex02
{
public class Farm <T> : IEnumerable <T>
where T : Animal
{
private List <T> animals = new List <T>();
public List <T> Animals
{
get
{
return animals;
}
}
public IEnumerator <T> GetEnumerator()
{
return animals.GetEnumerator();
}
IEnumerator IEnumerable .GetEnumerator()
{
return animals.GetEnumerator();
}
public void MakeNoises()
{
foreach (T animal in animals)
{
animal.MakeNoise();
}
}
public void FeedTheAnimals()
{
foreach (T animal in animals)
{
animal.Feed();
}
}
public Farm < Cow > GetCows()
{
Farm < Cow > cowFarm = new Farm < Cow >() ;
foreach (T animal in animals)
{
if (animal is Cow )
{
cowFarm.Animals.Add(animal as Cow );
}
}
return cowFarm;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace ch12ex02
{
public class SuperCow : Cow
{
public void fly()
{
Console .WriteLine( "{0} is flying" , name);
}
public SuperCow( string newName)
: base (newName)
{
}
public override void MakeNoise()
{
Console .WriteLine( "{0} says here i come to save the day !" , name);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace ch12ex02
{
class Program
{
static void Main ( string [] args)
{
Farm < Animal > farm = new Farm < Animal >();
farm.Animals.Add( new Cow ( "Jack" ));
farm.Animals.Add( new chicken ( "vera" ));
farm.Animals.Add( new chicken ( "Sally Ally" ));
farm.Animals.Add( new SuperCow ( "Kevin" ));
farm.MakeNoises();
Farm < Cow > dairyFarm = farm.GetCows();
dairyFarm.FeedTheAnimals();
foreach ( Cow cow in dairyFarm)
{
if (cow is SuperCow )
{
(cow as SuperCow ).fly();
}
}
Console .ReadKey();
}
}
} Tag: Visual C# General Simple Form writting to a csv file. Visual C#

Debug vs Release Questions Just to be clear, are you running the application in debug mode with no problems vs running it in the debugger with no problems If you are only running it in the debugger, what happens when you run the debug code outside the debugger Also one can debug in .Net release mode does the same occur Do you have the project settings "Enabled Unmanaged Debugging" set to true or false What happens when you switch settings Tag: Visual C# General Simple Form writting to a csv file. Visual C#

Can I have custom setting type? Hi, Devin
Yes, you can. However the visual designer does not seem to support this so you have to do some manual work.
First you need to create a new application setting class that derives from ApplicationSettingsBase as follows:
How to: Create Application Settings
Then add your new type like this:
Code Snippet
[ApplicationScopedSetting()] [SettingsSerializeAs(SettingsSerializeAs.Binary)] [DefaultSettingValue(@"AAEAAAD/////AQAAAAAAAAAMAgAAAEpXaW5kb3dzQXBwbGljYXRpb240LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAHldpbmRvd3NBcHBsaWNhdGlvbjQuQ3VzdG9tRGF0YQIAAAAEbmFtZQR0aW1lAQANAgAAAAYDAAAAB0NTIFRhbmdZNHHJs83JiAs=")] public CustomData Data { get { return (CustomData)this["Data"]; } set { this["Data"] = (CustomData)value; } }
Note that how the data should be serialized is specified by the SettingsSerializeAs attribute. The default value is specified by DefaultSettingValue attribute. The value itself should be generated by yourself.
Finally you can retrieve the data with an instance of the new application settings class.
Code Snippet
CustomSettings cs = new CustomSettings();
CustomData lastData = cs.Data;
Best Regards
Chunsheng Tang Tag: Visual C# General Simple Form writting to a csv file. Visual C#

Improve this singleton wrapper Hi
in the code above you are kind of duplicating the singleton...
take a look at the following:
Code Snippet
public class Something{
private static Something _Instance = new Something();
public static String SomeMethod{
return _instance.SomeOtherMethod;
}
String SomeOtherMethod{
return "gimmegimme";
}
protected Something(){} }
some remarks:
- this is an implementation of a singleton, even if it doesn't have a public static property called Instance
as there can be but one instance at any time
- the static string SomeMethod has a different name than the instance method, as c# doesn't allow you to access static methods via instances
- this allows you to just call Something.SomeMethod
- you could create an additional method CreateInstance() that would need to be protected or private and called before passing a call to the instance field
Code Snippet
protected void CreateInstance(){
if(_instance == null){
_Instance = new Something()
}
}
However, this method is not really thread safe, as two threads can be accessing the CreateInstance method at the same time
what you really need to do is:
Code Snippet
private Object _lock = new Object();
protected void CreateInstance(){
if(_instance == null){
lock(_lock){
_Instance = new Something()
}
}
}
The code above comes from Jeffrey Richter's CLR via C# 2.0 (recommend reading)
Hope this helps you out Tag: Visual C# General Simple Form writting to a csv file. Visual C#

Got a question...!!! Nullable value types and foreach loop on them.... Hi, Thanks for your answer...It does make sense...Now I am just thinking about following things on this... 1) If this was the case, would it take microsoft 100 yrs to write this in their docs (MSDN, sdk etc...) This was important point and I checked the docs for foreach, They have not specified any such thing....Do u know why... Or its just the black hole called microsoft... 2) I rewrote the code and isntead of int32 I used String thinking that code will compile as before (since we can use any object in foreach ..) and at runtime it will throw exception...But to my surprise, it gave error saying that "can not convert int32 to String"...... Following is the code... class ArrayApp2 { static void Main(string[] args) { Int32 [] numbers = new Int32 [] { 10, null }; //Wont compile...Cant assign nullable int to int implicitly... //Int32 nullableInt = 10; //Int32 normalInt = nullableInt; ////Compiles well....Isnt this strange... But throws exception at runtime ... //foreach (Int32 number in numbers) //{ // Console.WriteLine(number); //} //this time it does not comiple....Cant convert Int32 to STring foreach (String number in numbers) { Console.WriteLine(number); } } } So how come this throw the compile time error if we can use any object in for each and it tries to convert it at runtime... Tag: Visual C# General Simple Form writting to a csv file. Visual C#

web service + dllimport = unable to load dll I should have mentioned it in my original post - I have tested absolute path without any luck. I have also tried putting it into my system32 directory as mentioned in the original post. Registering the dll is not possible as it's not a com dll. Tag: Visual C# General Simple Form writting to a csv file. Visual C#

Question on VS2005 designer I have come acrosss many instances of the designer failing to open a form when there is alot code in the load event of the form.
Comment out your code in the load and init methods and see if it stops your problems.
There is a way to make code only execute when not in design mode which is the solution for now however I can't remember the command.
You might as well check and see if this is the problem first of all. Tag: Visual C# General Simple Form writting to a csv file. Visual C#

Threads with more than 1 argument Thanks, that is exactaly what I was looking for.
But can you help me a little more, please
I was using Threads to do it, so I had this code to allow my threads to alter a component in the GUI. But now I don't knkow how to fix this code to work.
Can you help me avoiding the "Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on." exception please
Thanks, Oscar
if ( this .dataGridViewEntradas.InvokeRequired)
{
ParameterizedThreadStart parametrized = new ParameterizedThreadStart (InsereDados);
this .Invoke(parametrized, obj);
}
else
{
//work here. . . .
} Tag: Visual C# General Simple Form writting to a csv file. Visual C#

conditional attributes hi The Conditional attribute
The attribute Conditional enables the definition of conditional methods. The Conditional attribute indicates a condition by testing a conditional compilation symbol. Calls to a conditional method are either included or omitted depending on whether this symbol is defined at the point of the call. If the symbol is defined, the call is included; otherwise, the call (including evaluation of the parameters of the call) is omitted.
you can find the details here
http://msdn2.microsoft.com/en-us/library/aa664622(vs.71).aspx
thanks Tag: Visual C# General Simple Form writting to a csv file. Visual C#

Is there a way to convert a txt file into a bin file? Well,
In truly, I'd like to only convert the file (without to read). Because another specific application would read the information about this file content.
Thanks by attention.
Rui Tag: Visual C# General Simple Form writting to a csv file. Visual C#

Dll Import Problem In Loading two Assemblies with Same Name Hello all
"NewProject" (2.0) <=> Errors.dll (1.1) <=> Cmmn.dll (1.1)
<=> Cmmn.dll (2.0)
I once wrote an error-logging dll in .NET 1.1: "Errors.dll", which calls another dll "Cmmn.dll", also version 1.1
Now i re-use this "Errors.dll" from a new project, which is in .NET 2.0. This new project also needs to call functions from "Cmmn.dll", but in version 2.0...
How can i prevent conflicts
Thanks!
j. Tag: Visual C# General Simple Form writting to a csv file. Visual C#

C# Vista Issue Do you have a good web reference for me to look at to see how I would grant "admin" access to the user or at least prompt them for the admin password Tag: Visual C# General Simple Form writting to a csv file. Visual C#

WindowsControlLibrary security problems Is there anyway to ask the user if they trust my website/control so that they dont get the error message Tag: Visual C# General Simple Form writting to a csv file. Visual C#

Shortcut key problem. I have set the shortcut "(Ctrl+O, Ctrl+P)" for rebuilding a selected project, but when i have multiple managed projects in a solution then on pressing that combination of keys I get the error message "The key combination (Ctrl+O, Ctrl+P) is bound to command (Rebuild Only Project) which is not currently available." in status bar of visual studio. Does someone know why does it happen
Best Regards, Mushq Tag: Visual C# General Simple Form writting to a csv file. Visual C#

Threading Question why do you think it isn't starting on a seperate thread, does the UI of the application 'freeze' after creating the thread In fact does UI do anything after creating the thread or does it just sit there
IMO - the use of Application.DoEvents should be avoided, you shouldn't have to 'pump' messages around your application yourself, it is a hang over from VB when they couldn't process asynchronously in a form.
HTH
Ollie Riches Tag: Visual C# General Simple Form writting to a csv file. Visual C#

How to store a password? hi, rabin
It seems that you'd create a table in database to store the password information, or in other way store it in files as well.
BR Tag: Visual C# General Simple Form writting to a csv file. Visual C#

geneway

Ok to all of you windows CSharp Gurus......

I have a simple form that I want to write to a csv file in a hand held scanner device. In the on Submit I am not sure what to write in order to create the CSV for the given data that is in the form. any help will be of great assistance.