|
Hello
Could someone tell me please: How to create a Module class in C# similar to VB .NET?
Thanks in advance...
kind regards
lapeci
|
|
|
|
|
There's no such thing : create a public static class
Cheers
If you can read this, you don't have Papyrus installed
|
|
|
|
|
Hi Estys
Thanks for your reply.
I have have created the static class but im having a problem on one of my method inside this class maybe you can tell me if I'm missing something.
Here is the code of that method...
public override bool Equals(object obj)
{
UserClient temp = obj;
return (userPass == temp.userPass);
}
The error it gives me is:
Can not implicitly convert type 'object' to UserClient...
The UserClient is the static class...
Thanks again in advance
kind regards
lapeci
|
|
|
|
|
Try this :
public override bool Equals(object obj)
{
UserClient temp = (UserClient)obj;
return (userPass == temp.userPass);
}
You were missing casting. You have to explicitly cast the object to UserClient.
|
|
|
|
|
This is not safe, you risk exceptions if the cast fails.
Cheers
If you can read this, you don't have Papyrus installed
|
|
|
|
|
Hi Pravin
Thanks for your reply.
Could you please help me convert this Module of VB .NET in to C# ...
Module UserLoginOptionModule
Public CustomerList As ArrayList = New ArrayList()
Public ordersMap As Collections.Hashtable = New Hashtable()
' Global variables
Public UserNameVal As String
Public UserSurnameVal As String
Public UserTypeVal As String
Public UserRoomNoVal As String
Public UserNoOfCovers As String
Public UserId As Integer
Public CurrCustomer As Customer
End Module
thanks in advance
kind regards
lapeci
|
|
|
|
|
static class UserLoginOptionModule
{
public static ArrayList CustomerList = new ArrayList();
public static System.Collections.Hashtable ordersMap = new Hashtable();
public static string UserNameVal;
public static string UserSurnameVal;
public static string UserTypeVal;
public static string UserRoomNoVal;
public static string UserNoOfCovers;
public static int UserId;
public static Customer CurrCustomer;
} There is an online converter here[^] which will take most of the pain out of things. I sometimes use it to generate VB for Q&A answers.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Estys is right: use as instead:
public override bool Equals(object obj)
{
UserClient temp = obj as UserClient;
if (temp != null)
{
return (userPass == temp.userPass);
}
return false;
} You can also do it with is , but I prefer an explicit null check as it ensures the parameter is valid as well:
public override bool Equals(object obj)
{
if (obj is UserClient)
{
UserClient temp = (UserClient) obj;
return (userPass == temp.userPass);
}
return false;
}
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
You can't instantiate static classes, You can only refer to it's properties and methods.
So
UserClient temp = obj;
is wrong.
The error you're getting has nothing to do with that however.
UserClient temp = obj as UserClient;
if (!temp == null) { .. }
would work, but not for a static class. Similarly, in VB you can't 'create' a module.
see http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.80).aspx[^]
[edit] maybe it would work, never tried such a thing [/edit]
Cheers
If you can read this, you don't have Papyrus installed
|
|
|
|
|
Hi, You can not create Module class in C#.net as it was there in VB6 and now in VB.NET.
It may be because microsoft wanted to be purely Object oriented with C#. Instead you can create a Class Library for common functions and use it.
|
|
|
|
|
i have a question
using C# VS2010,
validate a textbox against IP AddresS(E.G local computer IP Address) on click event
input it into a textblock/label?
|
|
|
|
|
Yes.
What is your question?
What part of this is giving you a problem?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
validate a textbox against IP AddresS(E.G local computer IP Address) on click event
and on another click event
input it into a textblock/label?
|
|
|
|
|
Rei ho wrote: textbox
Use the TextBox.Text property.
string s = myTextBox.Text;
Rei ho wrote: IP AddresS
Use the IPAddress class: MSDN[^]
Rei ho wrote: input it into a textblock/label?
Use TextBox.Text property the other way:
myTextBox.Text = "It matches!";
I repeat: which part of this are you having difficulty with?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Seems to be an assignment from school
I cannot remember: What did I before google?
|
|
|
|
|
Quite likely; but I will give the OP the benefit of the doubt and assume that it's a language problem, given his name and location. If he still doesn't understand I will suggest the Chinese forum and see if that helps him / her.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Highlighting the text in random parts isn't enough. You need to let us know how far you've got with the code, what exceptions or problems you are having in it. We won't write the whole thing for you - we don't need to pass your class; you do.
|
|
|
|
|
private void okBtn_Click(object sender, RoutedEventArgs e)
{
string ipbox = IPBOX.ToString();
string ipAddress;
ipAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString();
if (string.Equals(ipbox,ipAddress))
{
ipAdd.Content = ipAddress;
}
else
{
Validates.Text ="Test";
}
}
Sorry, i really suck at programming,
i am using the coding that i typed above
But it keeps going to
Validates.Text="test" even when i type the correct String
|
|
|
|
|
Thanks, solved the problem myself
SOLVED
modified on Tuesday, January 25, 2011 10:17 PM
|
|
|
|
|
I have a DataGrid created in XAML like this:
<DataGrid Name="gridPersons" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="390" Height="440" IsReadOnly="True">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Width="180"></DataGridTextColumn>
<DataGridTextColumn Header="Age" Width="180"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
I also have a class to store data in:
class Person
{
public string name;
public int age;
public string phoneNumber;
public Person(string name, int age, string phoneNumber)
{
this.name = name;
this.age = age;
this.phoneNumber = phoneNumber;
}
}
As well as populated a list to keep some data in:
static void Main(string[] args)
{
List<Person> persons = new List<Person>();
persons.Add(new Person("John", 25, "123456789");
persons.Add(new Person("Tim", 20, "987654321");
}
Now I would like to foreach loop through the List<Person> into the DataGrid.
Each instance is a row in the grid and each row contains of only name and age property.
This was very easy in Windows Form Application, but in WPF I found this difficult
Any help?
|
|
|
|
|
Hello,
I am currently having a problem loading a video from a web server and then making it display on my expression blend 4 WPF C# application
Currently, the video is loaded out from within the application folders
Video.Source = new Uri(@".\Videos\Network\network_(a).wmv", UriKind.Relative);
Video.Play();
however i want to load it from a webserver and displaying it on my application
instead of @".\Videos\Network\network_(a).wmv"
what code should i use to change it
@"192.x.x.x\network_(a).wmv"
or perhaps using C# code to download from the web source and then display?
sorry, as i am relatively new in this field
|
|
|
|
|
For a start you will need to include the HTTP or FTP protocol you are using
"http://192.x.x.x\network_(a).wmv"
That will definitely help get closer to resolving the issue
Architecture is extensible, code is minimal.
|
|
|
|
|
I tried doing "http://192.x.x.x\network_(a).wmv"
However it doesn't load and plays the video
Again , the coding on my C# event handler is currently
Video.Source = new Uri(@".\Videos\Network\network_(a).wmv", UriKind.Relative);
Video.Play();
which loads the video from my video folder
|
|
|
|
|
Ok, did you change the UriKind to Absolute?
What is the Video object. Can you tell us the name of the video class and it's full namespace?
Rob
Architecture is extensible, code is minimal.
|
|
|
|
|
I want to extract numbers from a string [Shipment ID]
"string sentence = "Shipment ID: 212857,1212,Invoice No: 1202127, 25-JAN-10 (PDF) "
so the extracted numbers will be 212857 and 1212
I have tried with Regex but not getting the desired result.
Can anyone help
String data = Regex.Match(sentence , @"ID:\d{10}", RegexOptions.IgnoreCase).Value;
string[] digits = Regex.Split(sentence, @"\D+");
|
|
|
|